Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Man, that took some time to find in the docs:

Temporal.ZonedDateTime.prototype.withTimeZone() [0], which allows to convert from one timezone to another

   const meetingTime = Temporal.ZonedDateTime.from(
     "2021-08-01T12:00[America/New_York]",
   );

   const meetingTimeInParis = meetingTime.withTimeZone("Europe/Paris");
 
   console.log(meetingTimeInParis.toString()); // 2021-08-01T18:00:00+02:00[Europe/Paris]

To me, timezone translations as well as durations are such an essential thing which libraries must handle, and it's nice to see that Temporal handles both. But it looks like Temporal.Duration doesn't offer a custom `format` function, for example `duration.format('H\hmm\m')` or something like that to format a duration into 1h03m.

[0] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...



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.


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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: