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

groob opened this issue Nov 10, 2016 · 2 comments

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

groob opened this issue Nov 10, 2016 · 2 comments


Copy link

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

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"

What did you do?

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

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
Copy link
Contributor Author

groob commented Nov 12, 2016

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

// 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.

Copy link

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.
None yet

No branches or pull requests

3 participants