Closed dtext closed 1 month ago
Related Issues and Documentation
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Duplicate of #34913
@seankhliao is it though? I saw that issue and I also see that CEST is not defined within my (or my colleagues) system. But I'm not specifying some unknown timezone myself, I'm just passing on the value returned by time.Now().Zone()
. Why does that return CEST if my system doesn't know that timezone?
The time package is just reflecting that time zone information stored on your system.
The Zone
method is documented to return the abbreviated timezone name. The abbreviated names are not unique. In general there is no way to load a timezone using just the abbreviated name.
What we may not have is a way to return the full name of the local timezone. That is actually not recorded in the tzdata on a typical Unix system. You can often find it on a Unix system by calling os.Readlink("/etc/localtime")
.
Go version
go version go1.23.0 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
I'm in the Europe/Berlin Timezone, where the daylight savings time is called "CEST" as reported by
time.Now().Zone()
. I also tested with Europe/Bucharest ("EEST").https://go.dev/play/p/_RHfB4rcJzi
What did you see happen?
Running the code right now during daylight savings time yields:
tz: CEST, offset: 7200loc: UTC, err: unknown time zone CEST
. (Please excuse the formatting here, I threw this together quickly.)Running it with the clock set to March 1, and timezone updated to CET accordingly yields:
tz: CET, offset: 3600loc: CET, err: %!s(<nil>)
What did you expect to see?
I should always be able to load a location from a timezone string obtained by
time.Now().Zone()
during Daylight Savings Time the same as during Winter Time. In other words, I would expect the first result to be something like:tz: CEST, offset: 7200loc: CEST, err: %!s(<nil>)