luxon icon indicating copy to clipboard operation
luxon copied to clipboard

#651: Create ISO 8601 Date/Time Values w/o Milliseconds

Open nbcarey opened this issue 3 years ago • 2 comments

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.

nbcarey avatar Jul 29 '20 02:07 nbcarey

CLA assistant check
All committers have signed the CLA.

jsf-clabot avatar Jul 29 '20 02:07 jsf-clabot

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

loynoir avatar Mar 04 '22 12:03 loynoir

Still missing that feature..

ahmetzambak avatar Jan 04 '23 12:01 ahmetzambak

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.

icambron avatar Jan 04 '23 21:01 icambron