Skip to content
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

GMT Offsets appear to work in opposite direction #62

Closed
taylorkline opened this issue Aug 17, 2022 · 10 comments
Closed

GMT Offsets appear to work in opposite direction #62

taylorkline opened this issue Aug 17, 2022 · 10 comments

Comments

@taylorkline
Copy link

Great apologies, but I don't have time to create a reproducible example, but as a quick summary:

tzMock.register("US/Eastern");
format(new Date("2022-08-17"), "yyyy-MM-dd HH:mm:ssXXX");
// => "2022-08-16 20:00:00-04:00"

// on the other hand
tzMock.register("Etc/GMT-4");
format(new Date("2022-08-17"), "yyyy-MM-dd HH:mm:ssXXX");
// => "2022-08-17 04:00:00+04:00"
@Jimbly
Copy link
Owner

Jimbly commented Aug 17, 2022

What's format? Assuming it's another library, depending on what it's doing, you may need to register the mock'd date object before requiring it, or possibly something else is going wrong...

@taylorkline
Copy link
Author

It's from date-fns and used like:

import { format } from "date-fns";

@ghost
Copy link

ghost commented Aug 18, 2022

I can reproduce this issue

https://codesandbox.io/s/cold-water-lo0c8m?file=/src/index.js

@Jimbly
Copy link
Owner

Jimbly commented Aug 19, 2022

If it's just a data issue, not a formatting issue, perhaps the data added in #57 by @jacobwahoo wasn't right (flipped sign)?

@jacobwahoo
Copy link
Contributor

jacobwahoo commented Aug 29, 2022

I know it's weird, but for the Etc/GMT offsets, the convention is to reverse the direction. Don't ask me why.

Here's a list on IBM's website. You can see that Etc/GMT+12 is equivalent to GMT-12:00, Etc/GMT+11 is equivalent to GMT-11:00, etc.

https://www.ibm.com/docs/en/cloudpakw3700/2.3.0.0?topic=SS6PD2_2.3.0/doc/psapsys_restapi/time_zone_list.html

Here's a post on the Oracle community about how confusing it is:
https://community.oracle.com/tech/developers/discussion/3563188/etc-gmt-time-zones-confusing

So the time zones are fine. It's the convention that's messed up.

Edit: This was linked on one of those pages: https://opensource.apple.com/source/system_cmds/system_cmds-230/zic.tproj/datfiles/etcetera

I'm looking in my /usr/share/zoneinfo folder (which is where the script in this project generates time zones from), and It looks to me like /Etc is the only place with a complete set of static offsets, so I'm not sure there's a good way around this without just using non-standard abbreviations.

Here is a tree of the zoneinfo folder from Ubuntu if anyway wants to doublecheck https://gist.github.com/jacobwahoo/dd5ae4c9bf2630b9919c51d606d50b02

@taylorkline
Copy link
Author

Thank you @jacobwahoo .

Given that amazing answer I believe my issue here can be safely closed, unless anyone disagrees.

@jacobwahoo
Copy link
Contributor

It might be worth updating the README to say that they are backwards from what you might expect. Maybe we can avoid this confusion in the future

@Jimbly
Copy link
Owner

Jimbly commented Aug 30, 2022

Wow, that is confusing! Are there better numerically-named timezones to use instead of Etc/GMT+ that should be used here? If not, just a note in the README.md is probably a good idea =).

@jacobwahoo
Copy link
Contributor

@Jimbly Not that I saw, but my comment above has an enumeration of the timezone folder from my Ubuntu WSL instance if you want to look for yourself.

@Jimbly
Copy link
Owner

Jimbly commented Sep 6, 2022

Okay, thanks for checking. I've added a note to the README and will consider this closed =).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants