Closed ghts closed 5 years ago
msgPack lose location value with time.Time and return 'UTC'.
(Go 1.11.5, Windows 10 64bit)
I found this symptom after 'go get -u'.
Meanwhile, Json keep time location value, which is normal.
func TestMsgPackTime(t *testing.T) { msgPackHandler := new(codec.MsgpackHandle) msgPackHandler.WriteExt = true buffer := new(bytes.Buffer) original_value := time.Now() codec.NewEncoder(buffer, msgPackHandler).Encode(original_value) copied_value := time.Time{} codec.NewDecoderBytes(buffer.Bytes(), msgPackHandler).Decode(&copied_value) fmt.Printf("'%v' : '%v'\n", original_value.Location(), copied_value.Location()) }
This test prints < 'Local' : 'UTC' >.
I thinks this should be < 'Local' : 'Local' > just like JsonTest below.
func TestJsonPackTime(t *testing.T) { JsonPackHandler := new(codec.JsonHandle) buffer := new(bytes.Buffer) original_value := time.Now() codec.NewEncoder(buffer, JsonPackHandler).Encode(original_value) copied_value := time.Time{} codec.NewDecoderBytes(buffer.Bytes(), JsonPackHandler).Decode(&copied_value) fmt.Printf("'%v' : '%v'\n", original_value.Location(), copied_value.Location()) }
This test prints < 'Local' : 'Local' > as expected.
See https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type
msgpack defines a time extension, that only stores UTC time. So this is a limitation of the format.
Got it.
msgPack lose location value with time.Time and return 'UTC'.
(Go 1.11.5, Windows 10 64bit)
I found this symptom after 'go get -u'.
Meanwhile, Json keep time location value, which is normal.
This test prints < 'Local' : 'UTC' >.
I thinks this should be < 'Local' : 'Local' > just like JsonTest below.
This test prints < 'Local' : 'Local' > as expected.