Removing time zone canonicalization in `Intl.DateTimeFormat` will change behavior of Temporal polyfills
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 3.7k
- Forks
- 177
- PR merge metrics
- No merged PRs in 30d
Description
Currently, polyfills rely on time zone canonicalization of Intl.DateTimeFormat to implement Temporal's time zone canonicalization used in TimeZoneEquals.
the reference polyfill:
@js-temporal/polyfill:
temporal-polyfill:
https://github.com/fullcalendar/temporal-polyfill/blob/03c0f8e2075266b06d7e578a47a2e41fb472d8c7/packages/temporal-polyfill/src/internal/compare.ts#L222 and https://github.com/fullcalendar/temporal-polyfill/blob/03c0f8e2075266b06d7e578a47a2e41fb472d8c7/packages/temporal-polyfill/src/internal/timeZoneId.ts#L28
temporal-polyfill-lite:
However, Temporal proposal is removing canonicalization in Intl.DateTimeFormat (original PR is https://github.com/tc39/proposal-canonical-tz/pull/15), so behavior of polyfills will change when time zone canonicalization proposal will be shipped, especially in projects using a Temporal polyfill as a ponyfill or in the way which overwrites the native implemetation (e.g. importing temporal-polyfill/global overwrites globalThis.Temporal even if the native implementation exists).
First question is "will this change break the web?". It is definitely a normative change, but I suspect that virtually no project will be affected:
- I think comparing
ZonedDateTimeof two linked time zones is a rare use case. - Time zone canonicalization in polyfills doesn't work as expected across browsers in the first place, because JSC doesn't canonicalize time zones in
Intl.DateTimeFormat(I didn't dig into this discrepancy but maybe because JSC ships time zone canonicalization proposal before Temporal?). - I guess no library other than Temporal polyfills rely on canonicalization behavior
new Temporal.ZonedDateTime(0n, "Europe/Kiev").equals(new Temporal.ZonedDateTime(0n, "Europe/Kyiv"));
// `true` in V8 and SpiderMonkey (native implementation and polyfill)
// `false` in latest JSC (polyfill)
If this normative change is safe, second question is "How should polyfills deal with this upcoming change?".
A significant numbers of developers seem to want to use a Temporal polyfill as a ponyfill, so they may use polyfills even in the future version of browsers after time zone canonicalization proposal will be shipped.
The only solution I came up with is delegating TimeZoneEquals to the native Temporal implementation if it exists. It sounds very weird that a Temporal polyfill relies on native Temporal implementation though.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with TimeZoneEquals and the canonicalization paths in polyfill/lib/ecmascript.mjs, lib/ecmascript.ts, compare.ts, timeZoneId.ts, and timeZones.ts. Reproduce the Europe/Kiev versus Europe/Kyiv comparison across the cited engines and review the Intl.DateTimeFormat change. Done means documenting whether the normative change is safe and deciding how polyfills should handle it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100