-
Notifications
You must be signed in to change notification settings - Fork 18k
time.Equal is false after MarshalJSON/UnmarshalJSON outside UTC; affected/package: time #64311
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
I believe this is working as intended, and the zero time is not expected to be valid |
You will have the same issue with any time before circa 1880. I used zero time here simply because it illustrates the issue even more clearly. I just tried with: I would also question why is midnight 1st Jan year 1 so special that it is "not valid" but that is perhaps beside the point. For completeness sake: t1 := time.Date(1492, 10, 12, 8, 47, 59, 0, time.Local) b, _ := t1.MarshalJSON() var t2 time.Time t2.UnmarshalJSON(b) fmt.Printf("%v\n", t1.String()) fmt.Printf("%v\n", t2.String()) fmt.Printf("%v\n", t1.Equal(t2)) Prints (in my case): |
Duplicate of #57040 |
The following test is ok now and show the importance of using .UTC()
|
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, go1.21.4 is the latest as far as I can tell.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://go.dev/play/p/X1yF2C5EqyJ
Note the issue does not show in Go Playground because it is located in the UTC time zone.
What did you expect to see?
true
What did you see instead?
false
Notes:
I am aware of #12141, #10089, #17875. All of them seem to be discussing time.Equal vs == but in my case the actual time instant is different:
t1.wall is 0, t1.ext is 0
t2.wall is 0, t2.ext is 44
t1.IsZero() is true
t2.IsZero() is false
t1.String() gives "0001-01-01 00:57:44 +0057 LMT"
t2.String() gives "0001-01-01 00:57:44 +0057 +0057"
The strange 57:44 offset is, as far as I can tell, because time before time zones is converted to the local solar time. So this issue shows up only if you are located outside of UTC. I assume those weird fractional time zones are expected, based on this Stack overflow issue:
https://dba.stackexchange.com/questions/127965/why-does-time-zone-have-such-a-crazy-offset-from-utc-on-year-0001-in-postgres
The text was updated successfully, but these errors were encountered: