6 ms·
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.mozi
by desmondwillow 2y 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/Reference/Global_Objects/Intl/DurationFormat/format https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
I partially implemented it in the icu4x library.
- nekevss 2y agoAgreed 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 2y agoDurationFormat looks cool but it didn’t behave as I expected. https://github.com/tc39/proposal-intl-duration-format/issues/210 https://github.com/tc39/proposal-intl-duration-format/issues...
- burntsushi 2y agoAs 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