fullcalendar / temporal-polyfill

A lightweight polyfill for Temporal, successor to the JavaScript Date object
MIT License
369 stars 14 forks source link

`Instant#toLocaleString` defaults to UTC instead of local time zone #12

Closed stesen-wefunder closed 10 months ago

stesen-wefunder commented 2 years ago

According to the official Temporal documentation (emphasis mine):

Because Temporal.Instant does not carry a time zone, the time zone used for the output will be the timeZone property of options, if present; and otherwise, the current time zone from the environment, which is usually the system's time zone.

However, in this implementation calling toLocaleString() on an Instant with no arguments seems to default to UTC.

It seems to be happening on this line: https://github.com/fullcalendar/temporal/blob/ed6586020b157cf9ad647e2688dd869542c895f2/packages/temporal-polyfill/src/native/intlFactory.ts#L188

Based on my own manual testing with the Intl.DateTimeFormat API, as well as the MDN docs, simply removing the default and letting the time zone ID be undefined should provide this behavior automatically:

new Intl.DateTimeFormat(undefined, {
    year: "numeric",
    month: "numeric",
    day: "numeric",
    weekday: undefined,
    hour: "numeric",
    minute: "2-digit",
    second: "2-digit",
    timeZoneName: "long"
}).format(Date.now())
// => "5/19/2022, 6:02:01 PM Pacific Daylight Time"
arshaw commented 1 year ago

Confirmed, this is a bug. I'll fix in the next round of code changes: https://github.com/fullcalendar/temporal#project-update-2023-04-22

arshaw commented 10 months ago

This has been fixed in v0.2.0.

Please let me know once you confirm. Thanks!