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

time: The Time object created with time.Date() in the timezone America/New_York returns incorrect information when DST is applied. #66554

Closed
changmink opened this issue Mar 27, 2024 · 1 comment

Comments

@changmink
Copy link

Go version

go version go1.22.1 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/user/Library/Caches/go-build'
GOENV='/Users/user/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/user/.gvm/pkgsets/go1.22.1/global/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/user/.gvm/pkgsets/go1.22.1/global'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/user/.gvm/gos/go1.22.1'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/user/.gvm/gos/go1.22.1/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.1'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/user/Projects/cronexpr/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/ds/8q7h4w3j0wggmj73zn46gt240000gn/T/go-build2556637787=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

When the timezone is set to America/New_York and the time is set to 2 o'clock using time.Date(), DST should be applied, resulting in an output of 3 o'clock, but it returns 1 o'clock instead. However, in other timezones, it works correctly.
Please Check. https://go.dev/play/p/kN_Cmgp8zny

What did you see happen?

I got the following result. It's the same response as the playground link attached above.

go run main.go
Sun, 10 Mar 2024 01:00:00 EST
Sun, 10 Mar 2024 01:00:00 EST
Sun, 31 Mar 2024 01:00:00 CET
Sun, 31 Mar 2024 03:00:00 CEST

What did you expect to see?

The response I consider to be correct is as follows.

Sun, 10 Mar 2024 01:00:00 EST
Sun, 10 Mar 2024 03:00:00 EDT
Sun, 31 Mar 2024 01:00:00 CET
Sun, 31 Mar 2024 03:00:00 CEST
@ianlancetaylor
Copy link
Contributor

Thanks, but this is working as documented. Quoting https://pkg.go.dev/time#Date:

Date returns a time that is correct in one of the two zones involved in the transition, but it does not guarantee which.

@ianlancetaylor ianlancetaylor closed this as not planned Won't fix, can't repro, duplicate, stale Mar 27, 2024
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

2 participants