luxon
luxon copied to clipboard
#651: Create ISO 8601 Date/Time Values w/o Milliseconds
This addresses Issue #651 (Feature request - function to quickly create ISO8601 stamp without milliseconds).
It adds a precision
option, the domain of which is hours
, minutes
, seconds
, milliseconds
, defaulting to milliseconds
. Time components of higher precision than that specified are simply omitted: no attempt is made at rounding.
If precision
is specified in addition to suppressSeconds
or suppressMilliseconds
, the suppress*
option wins:
DateTime.utc({2020,7,25,12,34,0,0}).toISO({ precision: 'millisecond', suppressSeconds: true })
returns 2020-07-25T12:34Z
.
Millisecond precision was requested, with the proviso that seconds and milliseconds won't be rendered if they are both zero.
Note: It might be a nice TO DO to add an auto
precision that would set the precision level to omit trailing components whose value is zero, so
Datetime.utc({2020, 7, 25, 12, 34, 0, 0}).toISO({ precision: "auto" })
would return 12:34Z
.
Hi, developers.
Will this useful pull be merged?
Maybe stripMilliseconds
?
- Less than 0.5,
11:22:33.444
-> 11:22:33 - Larger than 0.5,
11:22:33.666
-> 11:22:33
Still missing that feature..
To anyone finding this: this PR just needs a little work, as detailed in the comments. If you do that work, I'll merge it! In the meantime, asking for it more isn't going to help.