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

encoding/json: Marshalled time location inconsistent in GMT #17885

Closed
groob opened this issue Nov 10, 2016 · 2 comments
Closed

encoding/json: Marshalled time location inconsistent in GMT #17885

groob opened this issue Nov 10, 2016 · 2 comments

Comments

@groob
Copy link
Contributor

groob commented Nov 10, 2016

Please answer these questions before submitting your issue. Thanks!

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

1.7.3 (but tried tip as well)

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/victor/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/02/k62z5c796fs5gm651jc610v80000gn/T/go-build475244754=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

https://play.golang.org/p/gFDhc-65Ft

What did you expect to see?

When using json.Marshal on a time value, I expected the a myTime.Location() to always be Local when the host timezone is set.

What did you see instead?

If my local time is set to GMT, I see UTC instead of Local.

using time.Parse() as shown in the example seems to work correctly, but when the value is marshaled to/from JSON the output is inconsistent between timezone.

groob added a commit to kolide/fleet that referenced this issue Nov 11, 2016
enable redis and mysql tests in CircleCI environment
switch redis test to use UTC time - golang/go#17885
@groob
Copy link
Contributor Author

groob commented Nov 12, 2016

I tried time.Parse with RFC3339 time format, which makes the above clearer:

fmt.Println(time.Now().Format(time.RFC3339))
// Output in EST: 2016-11-12T11:12:37-05:00
// Output in PST: 2016-11-12T08:19:15-08:00
// Output in GMT: 2016-11-12T16:19:40Z

using time.Parse with 2016-11-12T16:19:40-00:00 prints Local correctly when in GMT.

@quentinmit
Copy link
Contributor

This is a dupe of #17875; Local and UTC are the same if your timezone is GMT, so encoding/json is working as intended. We make no guarantees about which location object is attached to times, only that a time that is t.Equal is returned.

@quentinmit quentinmit changed the title encoding/json Marshalled time location inconsistent in GMT encoding/json: Marshalled time location inconsistent in GMT Nov 15, 2016
@golang golang locked and limited conversation to collaborators Nov 15, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants