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: inconsistent handling timezone offset for a location #35152

Closed
w0st opened this issue Oct 25, 2019 · 2 comments
Closed

time: inconsistent handling timezone offset for a location #35152

w0st opened this issue Oct 25, 2019 · 2 comments

Comments

@w0st
Copy link

@w0st w0st commented Oct 25, 2019

What version of Go are you using (go version)?

go version go1.13.3 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/w0st/.cache/go-build"
GOENV="/home/w0st/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/w0st/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/snap/go/4668"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/snap/go/4668/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/w0st/Projects/project/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build558594662=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Hello, I want to convert local DateTime by parsing string (without having information about the timezone) and location string (like Europe/Paris) to a DateTime following ISO standard (with correct timezone information)

I'm trying this approach:

location, _ := time.LoadLocation("Europe/Paris")
parsedTime, _ := time.Parse("2006-01-02T15:04", "2019-10-25T13:45")

_, offset := time.Now().In(location).Zone()

result := parsedTime.Add(-time.Second * time.Duration(offset)).In(location).Format("2006-01-02T15:04:00-07:00")

fmt.Printf("Offset: %d\n", offset)
fmt.Printf("Result: %s\n", result)

I tested this on different versions of Go and the results aren't the same.

https://repl.it/repls/MediumpurpleObviousPriority
https://play.golang.org/p/WSG8Nb8R0TF

What am I'm doing wrong?

What did you expect to see?

Consistent outputs regardless Go version.

What did you see instead?

https://repl.it/repls/MediumpurpleObviousPriority
https://play.golang.org/p/WSG8Nb8R0TF

Offset: 7200
Result: 2019-10-25T13:45:00+02:00

or

Offset: 3600
Result: 2019-10-25T14:45:00+02:00
@dmitshur
Copy link
Member

@dmitshur dmitshur commented Oct 25, 2019

Hi there.

With the information provided here so far, this is more of a question about using the API of package time than a bug report in the package. More people will see your question, and you will get better answers, if you ask on Stack Overflow or another medium suggested at https://golang.org/wiki/Questions rather than on the issue tracker, since we use the issue tracker primarily for tracking bugs.

If it turns out to be a bug or a problem in time after all, please don't hesitate to re-open this and provide more details so we can investigate. Thanks.

@dmitshur dmitshur closed this Oct 25, 2019
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Oct 25, 2019

Don't ignore the error return values.

@golang golang locked and limited conversation to collaborators Oct 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.