moment / luxon

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

`DateTime.fromObject(..., zone)` does not set the zone to the created instance when using Chrome #1072

Closed khanhhuy closed 2 years ago

khanhhuy commented 2 years ago

Describe the bug DateTime.fromObject(..., zone) does set the zone to the newly created instance when using with Chrome. But it does set the zone when using with NodeJS

To Reproduce

Intl.DateTimeFormat().resolvedOptions().timeZone
// 'Asia/Saigon'
window.H.DateTime.fromObject({ year: 2021, month: 11, day: 4 }, { zone: "Europe/Paris" }).zoneName;
// 'Asia/Saigon'

Actual vs Expected behavior

Additional context Do the same test using NodeJS, and the zone name is set correctly.

// Command to run: env TZ='Asia/Saigon' node .

luxon2 = DateTime.fromObject({ year: 2021, month: 11, day: 4 }, { zone: 'Europe/Paris' })
console.log(luxon2.zoneName);
// Europe/Paris
icambron commented 2 years ago

How confident are you that the version of Luxon you have hanging on your window var is 2.0.2?

Try going to here, opening dev tools, and running this in your console:

luxon.DateTime.fromObject({ year: 2021, month: 11, day: 4 }, { zone: 'Europe/Paris' }).zoneName

That gives me "Europe/Paris".

Part of why I'm guessing this is a version issue is that Luxon v1.x required the zone option in the first arg instead of in the second arg. We changed that in 2.0 so that it's part of a second arg. So if you were accidentally using Luxon 1.x, you'd get this behavior.

khanhhuy commented 2 years ago

Hi @icambron, thank you for your reply. You're totally correct, my browser version is ^1.2.6. I'm having some other libraries that use luxon 2.0.2 and I wasn't aware of these inconsistencies. Thanks again for your help on this, I'll close this issue.