moment / luxon

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

Info.months return null[] on iOS if locale format is 'en-GB' #1486

Closed FrancoTanzarella closed 11 months ago

FrancoTanzarella commented 11 months ago

Describe the bug This happens on iOS only. Info.months('long', {locale: 'en-GB'}) returns an array filled with null but replacing en-GB with just en returns the month names. I can't get around this by stripping of -GB since we support other languages like es-CA, es-ES etc.

To Reproduce snack:

Actual vs Expected behavior expect the en-GB and other locales to work.

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

diesieben07 commented 11 months ago

This seems to be a problem with the implementation of Intl.DateTimeFormat#formatToParts. Take this code:

const dtf = new Intl.DateTimeFormat('en-GB', {month: 'long'});
console.log(dtf.formatToParts(new Date()));

V8 (i.e. NodeJS, Chrome and related browsers) and Firefox report the following:

[
  { "type": "month", "value": "August" }
]

In sandbox environment you shared, this code produces the following (incorrect, note the type key) result instead:

[
  { "type": "literal", "value": "August" }
]

I currently do not have the ability to test this on an actual iOS device (or Safari on macOS). But it seems you'll have to open a bug report in whichever environment causes this wrong result.

dasa commented 11 months ago

Safari 16.6 returns [{type: "month", value: "August"}]

diesieben07 commented 11 months ago

Thank you for testing, it sounds like this is yet another bug with Hermes.

FrancoTanzarella commented 11 months ago

Thanks for the feedback. I can get around this using globalize for the month and day names for now.

diesieben07 commented 11 months ago

You could also use this polyfill.