-
Notifications
You must be signed in to change notification settings - Fork 740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Timezones only work in certain circumstances #1363
Comments
There are two things happening here: the first is a bug in your class and the other is a bug in Luxon. But first, let's clear up a misunderstanding: OK, onto the actual issues: the first is the equality operator in your custom zone. let base = DateTime.fromMillis(0).setLocale('en-US');
console.log(base.setZone(new MyZone('America/Los_Angeles')).toISO()); //=> 1970-01-01T00:00:00.000Z
console.log(base.setZone(new MyZone('America/New_York')).toISO()); //=> 1969-12-31T19:00:00.000-05:00 That second one is totally ignoring your custom zone, which doesn't know that NY is ever at -5. You need to not just check the name but also ensure that the passed-in zone is a let base = DateTime.fromMillis(0).setLocale('en-US');
console.log(base.setZone(new MyZone('America/Los_Angeles')).toISO()); //=> 1970-01-01T00:00:00.000Z
console.log(base.setZone(new MyZone('America/New_York')).toISO()); //=> 1970-01-01T00:00:00.000+00:00
base = base.plus({ milliseconds: ONE_HOUR });
console.log(base.setZone(new MyZone('America/Los_Angeles')).toISO()); // => 1970-01-01T02:00:00.000+01:00
console.log(base.setZone(new MyZone('America/New_York')).toISO()); //=> 1970-01-01T02:00:00.000+01:00 That looks as expected. You aren't actually doing anything differently between NY and LA, so they are getting the same times. The isUniversal is causing Luxon to show a Z instead of a +00:00. The custom offset logic is working too. But once we put back in the
This is where it gets tricky. Luxon relies on Intl to spit out the string, but Intl doesn't understand custom zones. I suspect to fix this Luxon will need to treat custom zones as a fundamentally different thing. (Implementation notes for whoever fixes this: probably the best way to do this is to treat custom zones just like fixed-offset ones; i.e. we pass in the GMT zone nam to the intl formatter. This spares us doing a Finally, in terms of custom zones having better documentation and some more thorough guidance: completely agree. Someone just needs to do the work. |
Describe the bug
I'm not entirely sure if this is a bug or if this isn't intended to be a supported feature, but it seems like custom timezones are poorly supported (or at the very least, poorly documented). Particularly, there are a few things I'd like to point out about the behavior:
isUniversal
flag istrue
orfalse
.I did get the impression that custom timezones should be supported from reading this blurb about specifying a zone.
At the very least, I do think that if something comes out of this issue, it should be at least to update the documentation and perhaps add an example of how to implement custom timezones and their limitations. Or, to completely remove the blurb all together.
To Reproduce
Below is a basic set up for a custom timezone. In this case the behavior for
isUniversal
is not actually honored, all times will be offset by one hour after3600000
.There are four supported timezones, two of which are overrides:
Bogus/NotUniversal
,Bogus/Universal
,America/New_York
,America/Los_Angeles
.Actual vs Expected behavior
Again, I'm not sure what is a bug here and what isn't, it just appears there are just a lot of inconsistencies in behavior. So I'm just going to print what occurs:
Some notes:
isUniversal
istrue
the behavior always seems to produce the results I would expect, regardless of whether we are overriding a system timezone or adding a custom one.isUniversal
istrue
and the timezone is overriding a system timezone, it seems like the system time is used.isUniversal
isfalse
and the timezone is not overriding a system timezone, formatting the date causes an exception to be thrown.Additional context
For my particular use case, I would like to be able to override existing timezones and potentially add new ones if our version of tzdata is higher than that of the systems.
The text was updated successfully, but these errors were encountered: