Closed megla-tlanghorst closed 8 months ago
There are instructions in the release notes explaining the alternatives to that mechanism, depending on what time zone you want the formatting to be done in:
The change was originally made to avoid the ambiguity of which timezone to use when formatting the output - the timezone in the Intl.DateTimeFormat ctor, the time zone in the ZonedDateTime, or something else?
Can you elaborate on how creating a DateTimeFormat, converting the ZonedDateTime to an Instant, and formatting that Instant using formatToParts
doesn't work?
Is there any replacement (planned?) to replace this functionality.
There is a replacement in the pipeline, https://github.com/tc39/proposal-intl-zoneddatetimeformat, although it is at Stage 1 meaning the form of the replacement is not yet known.
That said, if you just need to extract the weekday names, I think you can still do that from a ZonedDateTime:
> Temporal.Now.zonedDateTimeISO().toLocaleString('en', {weekday: 'long'})
'Tuesday'
Can you elaborate on how creating a DateTimeFormat, converting the ZonedDateTime to an Instant, and formatting that Instant using formatToParts doesn't work?
Instants being UTC may flip weekdays, so I don't think that works?
Edit: Ahh I think I understand now, with the time zone of the format that should be avoided, thanks, the solution was there all along... Definitely excited to have some solid docs and guides in place once it ships.
That said, if you just need to extract the weekday names, I think you can still do that from a ZonedDateTime:
> Temporal.Now.zonedDateTimeISO().toLocaleString('en', {weekday: 'long'}) 'Tuesday'
That should work, thanks.
(You could also convert the ZonedDateTime to PlainDateTime, that would definitely not flip the weekday and you wouldn't have to set the time zone separately)
With the changes from 4.4, doesn't work anymore on
ZonedDateTime
. We useIntl.DateTimeFormat.formatToParts()
to extract names of the weekdays, which now doesn't work anymore.Is there any replacement (planned?) to replace this functionality.