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

DateTime.now() returns null for Asia/Kolkata IANA zone #1490

Closed BurgerZ closed 11 months ago

BurgerZ commented 11 months ago

Describe the bug DateTime.now() returns null if you try to set the timezone of Asia/Kolkata. It's not throwing any errors, just returns null.

To Reproduce

try {
    console.log("date:", DateTime.now().setZone("Asia/Kolkata"))
} catch (error) {
    console.log("error:", error)
}

Resulting log entry: date: null

Actual vs Expected behavior Expecting that it will result the actual date in selected time zone:

try {
    console.log("date:", DateTime.now().setZone("Europe/Madrid"))
} catch (error) {
    console.log("error:", error)
}

Output should be something like: date "2023-08-17T18:09:09.866+02:00"

Desktop (please complete the following information):

Additional context

diesieben07 commented 11 months ago

I cannot reproduce this in the iOS 16.4 simulator.

BurgerZ commented 11 months ago

I cannot reproduce this in the iOS 16.4 simulator.

Try this Expo snack - https://snack.expo.dev/@burgerz/luxon-datetime-issue

On web and Android it works well, but on iOS it shows just null instead of actual DateTime for Asia/Kolkata.

diesieben07 commented 11 months ago

Luxon uses Intl.DateTimeFormat to provide its localization and time zone data. React Native uses Hermes normally, not the default iOS WebView. Hermes' implementation of Intl.DateTimeFormat is unfortunately quite buggy and incomplete. In this case, new Intl.DateTimeFormat(undefined, { timeZone: 'Asia/Kolkata' }) throws under Hermes ("incorrect timeZone information provided"). You'll have to report a bug to Hermes.

Additionally I want to add, that DateTime.now() does not in fact return null. It returns an invalid DateTime. toISO on an invalid DateTime then produces null (because it has nothing else reasonable to show). If you inspect the invalid DateTime (DateTime#invalidReason) you will see that Luxon correctly reports "unsupported zone", because your platform does not support the time zone you requested.