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
@isayme
You can not override == operation in golang.
So with different(UTC) timezone, t1 == t2 return same true. can not be implemented only with golang code.
Please see the document: https://golang.org/ref/spec#Comparison_operators
Struct values are comparable if all their fields are comparable. Two struct values are equal if their corresponding non-blank fields are equal.
time.Time is a struct. So it will follow the rule. So t1 == t2 return false when timezone is UTC. because the loc field is not the same.
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.
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go1.9.2
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?linux amd64
What did you do?
https://play.golang.org/p/2mwUyy__IY2
What did you expect to see?
with different(UTC) timezone,
t1 == t2
return same true.What did you see instead?
t1 == t2
return false when timezone is UTC.The text was updated successfully, but these errors were encountered: