-
As in the title. We recently implement Luxon on a work project and when showing local times to UK folks the times either come out as GMT or GMT+1. In the US times are shown as either EST or EDT. So I'm just curious why Luxon uses a numbered offset for British Summer time and not just the BST abbreviation? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Luxon uses the built-into-the-runtime new Intl.DateTimeFormat("en-US", { timeZoneName: "short", timeZone: "America/New_York"}).format() //=> '10/1/2021, EDT'
new Intl.DateTimeFormat("en-UK", { timeZoneName: "short", timeZone: "America/New_York"}).format() //=> '01/10/2021, GMT-4'
new Intl.DateTimeFormat("en-US", { timeZoneName: "short", timeZone: "Europe/London"}).format() //=> '10/1/2021, GMT+1'
new Intl.DateTimeFormat("en-UK", { timeZoneName: "short", timeZone: "Europe/London"}).format() //=> '01/10/2021, BST' So how does Luxon choose what locale to use? Depends on the use case:
// you probably don't need the setZone(), but I do
DateTime.now().setZone("Europe/London").offsetNameShort //=> BST If your computer was set to some other locale, like mine, you could do: DateTime.now().setZone("Europe/London").setLocale("en-GB").offsetNameShort //=> BST You can also set the locale globally through the The same logic applies to
What's dumb here, of course, is that Intl doesn't have both sets of strings for both locales. But Luxon doesn't control that. |
Beta Was this translation helpful? Give feedback.
Luxon uses the built-into-the-runtime
Intl
API to get those strings. And annoyingly, the way the data backing that API works, it knows the offset abbreviations for the US if the locale is en-US and the offset abbreviations for the UK if the locale is en-GB: