moment / luxon

⏱ A library for working with dates and times in JS
https://moment.github.io/luxon
MIT License
15.48k stars 730 forks source link

UTC dates can't be locale formatted on iOS in Expo 51 #1633

Closed ntnp closed 6 months ago

ntnp commented 6 months ago

Describe the bug toLocaleString() stopped working for UTC dates on iOS in Expo 51. There are 4 attempts of Intl formatting in the example below: 2 using Intl directly (local and UTC) and 2 using Luxon (local and UTC). The UTC Luxon attempt fails on iOS in Expo 51. When toLocaleString() is called on a UTC date it apparently fails to instantiate Intl.DateTimeFormat correctly, throwing this.dtf.formatToParts is not a function (it is undefined).

To Reproduce Expo Snack Uncomment the <LuxonUtc /> component on SDK 50 and then on SDK 51.

Actual vs Expected behavior Expected: Calling toLocaleString() on a UTC date formats it. Actual: Calling toLocaleString() on a UTC date fails with an exception.

Desktop (please complete the following information):

Additional context Kinda looks like it's on Expo, but idk? It's weird that it affects iOS but not Android or Web.

ntnp commented 6 months ago

It's a Hermes issue. Fixed by pollyfilling Intl.DateTimeFormat:

// in index.js

require('@formatjs/intl-getcanonicallocales/polyfill');
require('@formatjs/intl-locale/polyfill');
require('@formatjs/intl-datetimeformat/polyfill');
require('@formatjs/intl-datetimeformat/locale-data/en');
require('@formatjs/intl-datetimeformat/add-golden-tz');
cseelus commented 5 months ago

It seems this works w/o the polyfill(s) now.