msgpack
msgpack copied to clipboard
Unmarshal an empty time object provides a problematic timezone
Unmarshal a byte array that was generated by marshaling an empty time struct If the unmarshal will receive an interface, this interface will eventually contain an empty time struct but with LMT timezone (that doesnt work properly in many cases) If the unmarshal will receive a time struct, this will work properly
Expected Behavior
empty time object in utc timezone
Current Behavior
empty time object in LMT timezone
Possible Solution
add tm.isZero case to the flow of unmarshaling from interface It does exists if a typed time struct is provided
Steps to Reproduce
See the following unit test:
func TestEmptyTimeMarshalWithInterface(t *testing.T) {
a := time.Time{}
b, err := msgpack.Marshal(a)
if err != nil {
t.Fatal(err)
}
var out interface{}
err = msgpack.Unmarshal(b, &out)
if err != nil {
t.Fatal(err)
}
name, _ := out.(time.Time).Zone()
if name != "UTC" {
t.Fatal("Got wrong timezone")
}
var out2 time.Time
err = msgpack.Unmarshal(b, &out2)
if err != nil {
t.Fatal(err)
}
name, _ = out2.Zone()
if name != "UTC" {
t.Fatal("Got wrong timezone")
}
}