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
Observing bizarre state mutations around the location in an instance of time.Time. By calling IsDST (which should be read-only, right?), the state of an instance is changed. Subsequent instances instantiated after the call to IsDST have an updated location and altered state.
before 11810389586750117723, after 12359862718078847701, new 12359862718078847701, pre 11810389586750117723
Showing that the hash of the instance changes after calling IsDST (Zone produces the same results). The hash of a new instance created after the call to IsDST on the first instance equals the new hash.
What did you expect to see?
A consistent hash and unaltered state when calling a seemingly read-only function.
What did you see instead?
A mysteriously changing hash value.
The text was updated successfully, but these errors were encountered:
What is the bug here? The time package explicitly says you should not do this:
// 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.
Thanks for the explanation and the documentation is quite clear. Just rather odd behavior. Calling UTC and/or Local had no effect. Adding this init function solved the problem:
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
)?go env
OutputWhat did you do?
Observing bizarre state mutations around the location in an instance of
time.Time
. By callingIsDST
(which should be read-only, right?), the state of an instance is changed. Subsequent instances instantiated after the call toIsDST
have an updated location and altered state.https://go.dev/play/p/bq0qA7JMJIz
With output as follows:
Showing that the hash of the instance changes after calling
IsDST
(Zone
produces the same results). The hash of a new instance created after the call toIsDST
on the first instance equals the new hash.What did you expect to see?
A consistent hash and unaltered state when calling a seemingly read-only function.
What did you see instead?
A mysteriously changing hash value.
The text was updated successfully, but these errors were encountered: