moment / luxon

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

Incorrect short format for timezone offset names #1560

Closed jdconley closed 6 months ago

jdconley commented 6 months ago

Describe the bug Luxon returns a GMT-based offset for a formatted timezone when I expect a friendly short name.

To Reproduce

Create a React Native app targeting Android with Hermes enabled.

import { DateTime, IANAZone } from 'luxon';

console.log(IANAZone.create('America/New_York').offsetName(DateTime.utc().getTime(), { format: 'short' }));

Actual vs Expected behavior On iOS this prints as expected (EST). On Android I see 'GMT-4' (as of posting).

Mobile

diesieben07 commented 6 months ago

Luxon can only provide data as good as the underlying platform. Hermes' implementation of the Intl.DateTimeFormat is unfortunately not great. If you check the output of the following snippet, you will see that it likely reports "GMT-4" for timeZoneName on Android when using Hermes:

const intl = new Intl.DateTimeFormat(undefined, { hourCycle: 'h23', year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', timeZone: 'America/New_York', timeZoneName: 'short' });
console.log(intl.formatToParts(new Date()));

You'll have to report this issue to Hermes.