You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ go version
go version go1.8.5 linux/amd64
$ go run main.go
gob:
Before: &main.someObjectWithTime{Time:time.Time{sec:63644866279, nsec:191418226, loc:(*time.Location)(0x572660)}}
After: &main.someObjectWithTime{Time:time.Time{sec:63644866279, nsec:191418226, loc:(*time.Location)(0x572660)}}
reflect.DeepEqual: true
What did you see instead?
$ go version
go version go1.9.2 linux/amd64
$ go run main.go
gob:
Before: &main.someObjectWithTime{Time:time.Time{wall:0xbe7585dacdb772e0, ext:1437579, loc:(*time.Location)(0x593820)}}
After: &main.someObjectWithTime{Time:time.Time{wall:0xdb772e0, ext:63644866283, loc:(*time.Location)(0x593820)}}
reflect.DeepEqual: false
The text was updated successfully, but these errors were encountered:
That's the expected behaviour, since encoding a time.Time strips the monotonic time part. See the part about comparisons in time.Time's documentation:
Note that the Go == operator compares not just the time instant but also the Location and the monotonic clock reading. Therefore, Time values should not be used as map or database keys without first guaranteeing that the identical Location has been set for all values, which can be achieved through use of the UTC or Local method, and that the monotonic clock reading has been stripped by setting t = t.Round(0). In general, prefer t.Equal(u) to t == u, since t.Equal uses the most accurate comparison available and correctly handles the case when only one of its arguments has a monotonic clock reading.
If you want to compare two time.Time instances you should use Time.Equal.
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.9.2 linux/amd64
Does this issue reproduce with the latest release?
Yes. It reproduces with Go version 1.9 and above.
What operating system and processor architecture are you using (
go env
)?What did you do?
https://play.golang.org/p/Bz82uni81C
What did you expect to see?
something like this:
What did you see instead?
The text was updated successfully, but these errors were encountered: