Hacker News new | ask | show | jobs
by desmondwillow 498 days 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.

2 comments

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).

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

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

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