-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
time: JSON marshaling/unmarshaling does not work reliably for zero Time value #57040
Comments
Thanks. This is failing because we use RFC 3339 format to marshal and unmarshal times, and that format can't represent the unusual sub-minute timezones used for Asia/Shanghai before 1901. I don't think we can fix this in general, but it may be worth handling the zero CC @dsnet |
I see at least four defensible behaviors:
Of the options, I like 2 and 4 the most. |
The doc for
And the implementation of So this issue is not about the zero |
I would argue that there are two clear bugs here:
|
I'm not sure I see that as a bug. My interpretation of
I agree with this. |
Is this really an issue? RFC 3339 Section 4.2 says this about time zones with second offsets
RFC 3339 Section 5.8 goes on to give an example of how it should be represented.
|
Maybe? I guess that depends on whether you expect |
Most developers likely expect roundtrip by default to work. For example https://play.golang.com/p/YpuQWEmy62S. Getting an LMT location as in that example is normal depending what machine it is running as far as I know. At the least some documentation in the time and/or json pkg would be very helpful. |
When a zero time value is loaded from JSON or a DB in a way that assigns it the local timezone, it does not roudtrip in JSON as a value for which IsZero returns true. This causes KeyExpiry to be treated as a far past value instead of a nilish value. See golang/go#57040
* Fix KeyExpiration when a zero time value has a timezone When a zero time value is loaded from JSON or a DB in a way that assigns it the local timezone, it does not roudtrip in JSON as a value for which IsZero returns true. This causes KeyExpiry to be treated as a far past value instead of a nilish value. See golang/go#57040 * Fix whitespace * Ensure that postgresql is used for all tests when env var is set * Pass through value of HEADSCALE_INTEGRATION_POSTGRES env var * Add option to set timezone on headscale container * Add test for registration with auth key in alternate timezone
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?
https://go.dev/play/p/Xsu1BBKI26i
What did you expect to see?
----- Before MarshalJSON -----
0001-01-01 08:05:43 +0805 LMT
LMT 29143
true
----- After UnmarshalJSON -----
0001-01-01 08:05:43 +0805 +0805
29143 // should be 29143
true // IsZero() should return true
What did you see instead?
----- Before MarshalJSON -----
0001-01-01 08:05:43 +0805 LMT
LMT 29143
true
----- After UnmarshalJSON -----
0001-01-01 08:05:43 +0805 +0805
29100 // lost 43 seconds
false // then IsZero() == false
The text was updated successfully, but these errors were encountered: