js-temporal/temporal-polyfill

`Intl.DateTimeFormat` inconsistency with proposal polyfill

HendrikThePendric opened this issue · 2 comments

I was trying something based on this example. The following code looked like it should work correctly:

const formatter = new Intl.DateTimeFormat('nl-NL', {
    weekday: 'long',
    day: 'numeric',
    month: 'long',
    year: 'numeric',
    calendar: Temporal.Calendar.from('gregory'),
    timeZone: Temporal.TimeZone.from('Europe/Amsterdam'),
})
const now = Temporal.Now.zonedDateTime('gregory')
    .withTimeZone('Europe/Amsterdam')
    .startOfDay()
    .toInstant()

formatter.format(now)

And in fact it does if I try it out in the console on the T-39 proposal page. It outputs vrijdag 20 mei 2022. This page is using the non-production polyfill.

However, when I try the exact same code in an app which is using this polyfill (js-temporal/temporal-polyfill), I get the following error when I run the exact same code: Uncaught TypeError: use compare() or equals() to compare Temporal.Instant and the error originates in instant.js line 172.

I have no idea if the code above is actually correct, but at the very least I would expect both polyfills to provide the same behavior.

I needed to also import the polyfilled version of Intl, so

import { Temporal, Intl } from '@js-temporal/polyfill' 

Not sure it was in the docs, but actually pretty obvious. Hindsight is 20/20 I guess.

Glad you figured it out!

The import incantation is in the README but if there's another place it should go that would have been more logical to you, we should put it there as well.