Skip to content

time: time.LoadLocation reports unknown time zone for European Summer Time #69549

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

Closed
dtext opened this issue Sep 20, 2024 · 4 comments
Closed

Comments

@dtext
Copy link

dtext commented Sep 20, 2024

Go version

go version go1.23.0 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE='on'
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/dtextores/Library/Caches/go-build'
GOENV='/Users/dtextores/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/dtextores/go/pkg/mod'
GONOPROXY='redacted'
GONOSUMDB='redacted'
GOOS='darwin'
GOPATH='/Users/dtextores/go'
GOPRIVATE='redacted'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/opt/go/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/opt/homebrew/opt/go/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.23.0'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/dtextores/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/dtextores/code/redacted/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/0g/tnsylx9n7qn2m0j4gmp452gh0000gn/T/go-build1406944028=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

package main

import (
	"fmt"
	"time"
)

func main() {
	tz, offset := time.Now().Zone()
	fmt.Printf("tz: %s, offset: %d", tz, offset)
	loc, err := time.LoadLocation(tz)
	fmt.Printf("loc: %s, err: %s", loc, err)
}

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>)

@seankhliao
Copy link
Member

Duplicate of #34913

@seankhliao seankhliao marked this as a duplicate of #34913 Sep 20, 2024
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Sep 20, 2024
@dtext
Copy link
Author

dtext commented Sep 23, 2024

@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?

@ianlancetaylor
Copy link
Member

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").

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

4 participants