-
-
Notifications
You must be signed in to change notification settings - Fork 480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add leading zero to hour & minute on <title /> when needed #314
Add leading zero to hour & minute on <title /> when needed #314
Conversation
…) to cut it off when not needed
…bpack-bundle-analyzer into bugfix/page-title-hours-minutes
Thanks for mention this. It is nice format to read. And what about ES6 '4'.padStart(2, 0); // result: '04' In this case, they are both OK, anyway. |
That's even better and much cleaner, thanks for the suggestion. I quickly checked the MDN docs and they state that Is it safe to say this will work in both cases (server & client) since src/viewer.js is 'server-side' code thus not affecting IE? |
We doesn't support IE11 in client bundle so it's completely safe to use padStart. |
Ok, thanks for the quick response @th0r. I've pushed another commit where I used template literals to convert the number to a String.
I can change this to the following if preferred:
|
Tag templates are ok, but let's better change method calls to |
According to tests, And there is also an ESLint error. |
Hi @mhxbe, it would be great to get this bug fixed |
Hi @valscion, I've been busy past week(s) but I will get this fixed tonight. If you've got time to fix this now, feel free to open up a new PR with the fix. I'll happily close this one then. If this is not the case, I will fix this tonight. |
Don't worry about the commit history |
@valscion I pushed a commit which reverts the |
My merge conflict resolve had a hickup 😅
Ok this seems good to go to me! Thanks |
Hi,
Recently @gaokun requested/added a date in the <title /> tag which is a great addition to the tool.
Last night, when I was using webpack-bundle-analyzer on a personal project, I saw the following date:
Problem
By default,
.getHours()
&.getMinutes()
return a number which results in a one-digit for all numbers lower than 10. In this case, it's displaying 1:5 for the hour & minutes whereas 01:05 would be nicer.Possible solution
Adding a leading zero in combination with converting it to a String, leverages us the usage of
.slice(-2)
so it returns the last 2 digits.Another solution is the usage of .substr(-2) but it seems this method will be deprecated in the future
Source for
.slice()
: String.prototype.slice()Source for
.substr()
: String.prototype.substr()If there are better approaches, I'm open for them.
Examples
You can copy paste the following code-snippet in your browser console to see it in action.