On Fri, Nov 27, 2020 at 4:14 PM 'Robert Ma' via golang-nuts <
[email protected]> wrote:

> Is this because the 2-second offset of LMT gets lost in RFC 3339
> representation?
>

Yes, that's exactly it.


> On Fri, Nov 27, 2020 at 6:33 PM Robert Ma <[email protected]> wrote:
>
>> Hi all,
>>
>> Time is complicated.
>>
>
Wibbly-wobbly, even.

Today I found myself in a rabbit hole. For some unrelated reason, I got a
>> time value in a non-UTC location that's otherwise zero (IsZero=true). This
>> value doesn't seem to survive a roundtrip to JSON. See this playground for
>> a minimal reproduction: https://play.golang.org/p/QdglfKYkstS
>>
>> Is this expected, a bug, or an undefined behaviour? I checked RFC 3339,
>> which time uses as the JSON serialization format, and it seems to support
>> 0000AD to 9999AD, but I have to admit I know little about time.
>>
>
RFC 3339 doesn't support sub-minute timezone offsets, so it's not possible
to format the LMT zone precisely.

I am concerned that the time printed is incorrect by 2 seconds in this
case, and (I imagine) could be anywhere from 0 to 59 seconds off depending
on the particular sub-minute timezone offset used. That seems like a real
bug, and I don't know what a proper fix would look like. Perhaps when the
timezone is formatted in numeric form, the printed time should be adjusted
to account for the loss of precision in the zone info. In your case this
would print "0000-12-31T19:04:00-04:56" instead
of "0000-12-31T19:03:58-04:56". That solution has its own issues though.

You probably should only use IsZero() to detect uninitialized time values;
never on a value that's been parsed from any source, even JSON.

To get arbitrary time values to survive a JSON round trip, I think using
UTC exclusively would be the best option.


>> Cheers,
>> Robert
>>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/CAOPAaN%2BWvZ73Z-oMVaGmDt-Gr5DEk7ZtQeU43x5fKrCFW42%3DqQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/golang-nuts/CAOPAaN%2BWvZ73Z-oMVaGmDt-Gr5DEk7ZtQeU43x5fKrCFW42%3DqQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CALRNMm0VN8030%2BQLY0sLr%2BuHfz4WoG7NfWe1RUHj-d2Zqh393Q%40mail.gmail.com.

Reply via email to