top | item 42879052

(no title)

desmondwillow | 1 year ago

The DurationFormatter proposal allows you control over which units you want formatted and at what brevity: eg. 1 yr, 3 hours, and 3m. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

I partially implemented it in the icu4x library.

discuss

order

nekevss|1 year ago

Agreed this sounds like they are looking for Intl.DurationFormatter.

Temporal.Duration.prototype.toLocaleString will end up using Intl.DurationFormatter though, so that will ultimately be what he wants (probably going to depend on that ICU4X implementation being complete though).

styfle|1 year ago

DurationFormat looks cool but it didn’t behave as I expected.

https://github.com/tc39/proposal-intl-duration-format/issues...

burntsushi|1 year ago

As the comment mentions there, the idea is that you can do those sorts of transformations on the duration and then emit them:

    >> d = Temporal.Duration.from({milliseconds: 60000})
    >> d.seconds
    0
    >> d.milliseconds
    60000
    >> d = d.round({largestUnit: 'second'})
    >> d.seconds
    60
    >> d.milliseconds
    0