-
Notifications
You must be signed in to change notification settings - Fork 18k
time: Parse with 0 UTC offset different on darwin vs linux #30114
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
Comments
@briancharous , could it be that your Darwin machine is configured with a local time zone that is not UTC? You can find out Go's notion of the local time zone e.g., by doing The manual says that numerical offsets only result in the local location:
So in case your local configuration is not TZ=UTC on Darwin, then your result is as documented. Now, is this behavior the expected and the right thing to do? There is not a mapping from numerical offset to location (TZ), because there are many locations (TZ) with different time zone rules. For example, your example "2019-02-06T14:00:00+00:00" could either be UTC as you expected, or it could be London, or Reykjavik and so on. There is an important difference here in that if you say ask what time it is five months from the date, then different locations may have different answers, as UTC and Reykjavik (at the example date and currently) do not do daylight saving time, while London does. I do think it is a bit risky for time parsing to behave differently like this depending on the location of the machine running it, and that it could be safer to never turn a numeric offset into a location. But, I guess that is what is most often wanted by the user. There is Here is a playground example based on your code that demonstrates what happens: https://play.golang.org/p/dNIj1QxBxJ1 |
@briancharous , Brian, Could you please have a look at this and my analysis, and comment whether this is a real bug or whether it was just a misunderstanding about the admittedly confusing behavior of |
@antong Yeah I think your analysis of this makes sense. The Mac I was testing this on's clock is not set to UTC, while the Linux "machine" (really a Docker container running in Docker for Mac) has its system clock set to UTC. |
I think this is investigated enough, solved and can be closed. |
I agree that this is working as documented. Closing here. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Parsing RFC3339 timestamps with 0 UTC offset specified as
+00:00
or-00:00
(for example2019-02-06T14:00:00+00:00
) produces a differenttime.Time
on Darwin vs Linux. On Darwin, the time gets parsed into atime.Time
with a custom zone with offset of 0 and no name, on Linux the timestamp parses (correctly in my opinion) into atime.Time
withtime.UTC
zone info.The behavior is correct on Darwin if the timestamp is specified with
Z
instead of an offset, for example:2019-02-06T14:00:00Z
parses into atime.Time
withtime.UTC
zone info.On Darwin, this program prints:
good TZ: UTC, good offset: 0, badTZ: , badOffset: 0
on Linux, this program prints:
good TZ: UTC, good offset: 0, badTZ: UTC, badOffset: 0
The text was updated successfully, but these errors were encountered: