-
-
Notifications
You must be signed in to change notification settings - Fork 65
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 colonNotation
option
#37
Conversation
test.js
Outdated
|
||
test('work with colon output option', t => { | ||
t.is(prettyMilliseconds(1000, {colonNotation: true}), '0:01'); | ||
t.is(prettyMilliseconds(1500, {colonNotation: true}), '0:01.5'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not match what the readme says, which is 5:01:45
. Why wouldn't seconds be in the same format as minutes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hours, minutes and seconds are prefixed with :
, and anything below seconds are treated with regular decimals. So 5h 1m 45s
-> ´5:01:45´, but 5h 1m 45.5s
-> 5:01:45.5
etc. See the comment below for more context.
@@ -221,3 +221,15 @@ test('properly rounds milliseconds with secondsDecimalDigits', t => { | |||
t.is(fn((3600 * 1e3) - 1), '1 hour'); | |||
t.is(fn((2 * 3600 * 1e3) - 1), '2 hours'); | |||
}); | |||
|
|||
test('work with colon output option', t => { | |||
t.is(prettyMilliseconds(1000, {colonNotation: true}), '0:01'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is minute zero prefixed, but hour is not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried googling for an official standard outlining how this format should behave, but was unfortunately unable to find one. However, the attached screenshot from the Kona Ironman World Championships this year shows what the commonly accepted convention is:
Here we can see, that Jan Frodeno's total time 2h 24m 45s
was 1s
behind whoever was leading at that time, which in this notation would be expressed as 2:24:45
and 0:01
respectively. This example doesn't show fractional seconds, but for seconds regular decimal formatting applies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with your assessment.
test.js
Outdated
t.is(prettyMilliseconds(1000 * 90, {colonNotation: true}), '1:30'); | ||
t.is(prettyMilliseconds(95500, {colonNotation: true}), '1:35.5'); | ||
t.is(prettyMilliseconds(95511.111, {colonNotation: true, formatSubMilliseconds: true}), '1:35.5'); | ||
t.is(prettyMilliseconds((1000 * 60 * 59) + (1000 * 59) + (500), {colonNotation: true}), '59:59.5'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see more tests, with this option combined with all the other options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a bunch of tests which actually revealed a few bugs in my code. I also made the code slightly more verbose, as I found it started becoming difficult to follow with all the conditionalities. I hope the refactored code is more legible.
Thanks for the review @sindresorhus , I'll address your comments shortly. |
readme.md
Outdated
@@ -104,19 +111,30 @@ Default: `false` | |||
|
|||
Use full-length units: `5h 1m 45s` → `5 hours 1 minute 45 seconds` | |||
|
|||
Setting `colonNotation` to `true` overrides this option. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readme.md
Outdated
##### separateMilliseconds | ||
|
||
Type: `boolean`\ | ||
Default: `false` | ||
|
||
Show milliseconds separately. This means they won't be included in the decimal part of the seconds. | ||
|
||
Setting `colonNotation` to `true` overrides this option. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of writing this for each option, I think it would be better to just document in the colonNotation
docs what options it overrides.
readme.md
Outdated
Type: `boolean`<br> | ||
Default: `false` | ||
|
||
Use colon notation: `5h 1m 45s` → `5:01:45` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description should be the same as in index.d.ts
- `compact` | ||
- `formatSubMilliseconds` | ||
- `separateMilliseconds` | ||
- `verbose` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember to keep index.d.ts in sync.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed some of the others were slightly out of sync (more comprehensive in readme), ok if I sync those at the same time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@sindresorhus I believe this is now ready; will be happy to make any additional changes if needed. |
This PR adds option to format using colon notation. Examples from
tests.js
: