-
Notifications
You must be signed in to change notification settings - Fork 103
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
time zones not working correctly #158
Comments
There's a lot going on here, and some of it is caused by the peculiarities of the timezone database. I presume you're using Unix in some form, because otherwise I believe none of this will work. One thing to understand (it's really subtle, and I am still missing some nuance; read on) is how time.Location works in Go. They are not time zones per se, they are locations in which time can be determined. Have a look:
First, note that my timezone, AEST, prints correctly. That's a property of the system, somehow, and for the life of me I can't figure out where it comes from. Second, note that it knows about EST and EDT but both print with the same offset, which is actually the current offset to UTC at the location in which EST is a valid time zone, e.g. New York. You can see this happening a bit in the test suite, which asks the time at the Unix epoch. The test has the wrong offset for that date, and will break when the US goes back to standard time. I should probably have commented that, and will return to it then. Third, I can't explain why you see zero for CEST, but on my machine CEST is not a known zone so I can't get ivy into that state. I can do this though:
Try that and see what you get. You could also try setting the TZ environment variable and explore what happens then. Despite this explanation, I do believe there are bugs, I just don't know how to deal with the inconsistencies in the timezone database and its interaction with what the local system says. |
I'm using macOS. If you have a macOS machine you should be able to my reproduce my behavior: System Settings -> General -> Date & Time
Now the time zone should be "Central European Summer Time" (until Oct 29). In the following experiments I'll use this short Go program for comparison with Ivy:
First experiment, with my system settings (location "Berlin - Germany"):
Here, the Go program prints what I expected, because CEST is UTC+2. In the next experiment, the time zone database doesn't seem to know about CEST and falls back to UTC if I specify TZ=CEST:
In the next experiment both interpret TZ=CET as a location (which I'm not a fan of, but perhaps I'll have to accept it) and switch to CEST:
The output of the short Go program is the consistent one. Next experiment with TZ=GMT:
In my understanding GMT is defined as UTC+0 and should always have the offset 0. However, Ivy interprets it as location "Europe/London", which is currently on British Summer Time (BST, UTC+1) rather than GMT. |
Thanks for the good report. I know what's wrong with GMT - I have it mapped to Europe/London instead of UTC - and that's trivial to fix. The others require more investigation. |
The following is my understanding when looking at this table: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
|
Since this lookup direction doesn't exist in the public API, I wondered if Go manages to parse "2023-09-27 18:00:00 CEST" correctly. So I ran the following program:
The output
is correct. Then I changed my location from "Berlin - Germany" to "New York, NY - United States" in the macOS system settings, and now the output is wrong!
I find it surprising that Go's time parsing, when provided with an explicit time zone, is dependent on the location setting. |
Yes, you've put your finger on something that's at the heart of this. I plan to investigate with the Go team. |
In config.TimeZoneAt, if an error occurs it silently set the time zone to UTC. This is a bad idea. Instead, give an error and change nothing. There is more to do here but let's get this cleared up now. Update #158
Turn it into location management, that is, track locations rather than time zones. The code is more robust now, and this fixes the output for the zero of Unix time in New York. However, there is still some thinking to do about time zones vs. locations in the UI. More may come, such as changing the special command to ")location". Update #158
I start Ivy and enter:
CEST is correct for my location, but offset 0 isn't. CEST is UTC+2, so the offset should be 7200.
Now I switch the time zone:
CET is expected, but offset 7200 isn't. CET is UTC+1, so the offset should be 3600.
Now I want to switch back to the original time zone:
Even though Ivy told me this zone name at the beginning, so it should be known.
The text was updated successfully, but these errors were encountered: