time
time copied to clipboard
Military (24-hour, ISO8601) time support
Hi there,
I implemented military time support
- new formatting parameters:
H
andHH
for military time hours - period formatters used in conjunction with military time formatters are ignored
- new getter/setter
militaryHours()
andmilitaryHours(hours)
- added a new method
toISOString()
that returns the ISO8601 time component (without seconds) - added military time tests
- removed a couple existing tests that were military time and now work correctly
- updated README.md with corrections for prior examples that were valid for military time, added new examples
It would be great if you would review and pull this in.
Thanks, Kimon
Realized an additional issue that needs fixing with regards to military time -
When parsing military time, for instance 03:00, since there is no way of knowing the difference between an input that was military time, and an input that is simply omitting the AM period, a design conflict arises. In your original design, you've chosen to parse a missing period as null
, whereas to support military time, it would have to be parsed as AM
. Without doing this, I can't parse military time (03:00) and then format it as 12-hour time with a period.
Here's a thought experiment and another reason that supports changing the design. If the internal storage of the time was ISO8601 compliant, then executing Time('3:00').format('h:mm am')
should produce the result 3:00 am
.
I'd like to know whether you are ok with introducing a breaking change. I'd be happy to update my PR. Was there a particular reason for this design decision? I noticed that you have a unit test testing this aspect (Time #format should ignore period if not originally parsed)
Thanks, Kimon
This really needs to be merged. not everyone in the world uses a 12 hour clock. US Military, hospitals, and pretty much 90% of the rest of the world use 24 hour time format.
Not supporting 24h is a pretty damning flaw in this package, what's worse is that the fix has been sitting here for nearly three years.
With some assurance that this PR would be looked at, I suppose I could find the time to look at whatever conflicts have come up over the last 2-3 years... :)
@kinergy why not go ahead and add yours to NPM... I'm already specifying your fork directly in my dependencies. something like time-js-24h would be nice.