-
Notifications
You must be signed in to change notification settings - Fork 18k
breaking change in go 1.9 about time marshal/unmarshal #22251
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
Comments
Possible duplicate of #20876, please see its discussion. |
This is expected behavior. You should not in general use
This discussion of It is true that this became less likely to work in Go 1.9, due to the introduction of monotonic time values. But it was never fully safe even before Go 1.9, due to the way that timezones are handled. Closing because this isn't going to change. |
Understand DeepEqual behavior. The question is more about why the time are changed after marshal/unmarshal. |
I assume because of the monotonic time values. See the "Monotonic Clock" section at https://golang.org/pkg/time. |
Don't understand why do we need to change the monotonic clock over marshal/unmarshal process? |
The monotonic time is meaningless in a different process, so we don't marshal it at all. |
Interestingly, time comparison with
Updated Go Playground using
MacOS locally:
|
@calvn I have a similar behavior with Arch Linux.
If I run the same code inside a Docker it behave as Playground. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?What did you do?
Marshal and Unmarshal a time.Time instance, they become different.
The use case is we use testify to setup mock expectation with a time as expected parameter. Then the tested code internally would do a marshal/unmarshal, and pass the value to the mock call. But the mock call would fail because the expectation does not met. The testify uses reflect.DeepEqual to compare if the parameters are match or not.
However, if you marshal/unmarshal a zero time, then before == after.
https://play.golang.org/p/dX_knLlRY-
This used to work fine with go 1.8
What did you expect to see?
a time instance after marshal/unmarshal (on same machine) should not change.
What did you see instead?
a time instance after marshal/unmarshal (on same machine) are different.
The text was updated successfully, but these errors were encountered: