...
1 package extra
2
3 import (
4 "github.com/json-iterator/go"
5 "github.com/stretchr/testify/require"
6 "testing"
7 "time"
8 )
9
10 func Test_time_as_int64(t *testing.T) {
11 should := require.New(t)
12 RegisterTimeAsInt64Codec(time.Nanosecond)
13 output, err := jsoniter.Marshal(time.Unix(1497952257, 1002))
14 should.Nil(err)
15 should.Equal("1497952257000001002", string(output))
16 var val time.Time
17 should.Nil(jsoniter.Unmarshal(output, &val))
18 should.Equal(int64(1497952257000001002), val.UnixNano())
19 }
20
21 func Test_time_as_int64_keep_microsecond(t *testing.T) {
22 t.Skip("conflict")
23 should := require.New(t)
24 RegisterTimeAsInt64Codec(time.Microsecond)
25 output, err := jsoniter.Marshal(time.Unix(1, 1002))
26 should.Nil(err)
27 should.Equal("1000001", string(output))
28 var val time.Time
29 should.Nil(jsoniter.Unmarshal(output, &val))
30 should.Equal(int64(1000001000), val.UnixNano())
31 }
32
View as plain text