2017-06-20 11:43:47 +02:00
|
|
|
package extra
|
|
|
|
|
|
|
|
import (
|
2017-06-20 18:26:18 +02:00
|
|
|
"github.com/json-iterator/go"
|
2017-07-07 03:13:25 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2017-06-20 11:43:47 +02:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_time_as_int64(t *testing.T) {
|
|
|
|
should := require.New(t)
|
2017-06-20 11:46:29 +02:00
|
|
|
RegisterTimeAsInt64Codec(time.Nanosecond)
|
2017-06-20 11:52:41 +02:00
|
|
|
output, err := jsoniter.Marshal(time.Unix(1497952257, 1002))
|
2017-06-20 11:43:47 +02:00
|
|
|
should.Nil(err)
|
2017-06-20 11:52:41 +02:00
|
|
|
should.Equal("1497952257000001002", string(output))
|
|
|
|
var val time.Time
|
|
|
|
should.Nil(jsoniter.Unmarshal(output, &val))
|
|
|
|
should.Equal(int64(1497952257000001002), val.UnixNano())
|
2017-06-20 11:43:47 +02:00
|
|
|
}
|
2017-06-20 11:46:29 +02:00
|
|
|
|
|
|
|
func Test_time_as_int64_keep_microsecond(t *testing.T) {
|
2017-06-26 08:25:56 +02:00
|
|
|
t.Skip("conflict")
|
2017-06-20 11:46:29 +02:00
|
|
|
should := require.New(t)
|
|
|
|
RegisterTimeAsInt64Codec(time.Microsecond)
|
|
|
|
output, err := jsoniter.Marshal(time.Unix(1, 1002))
|
|
|
|
should.Nil(err)
|
|
|
|
should.Equal("1000001", string(output))
|
2017-06-20 11:52:41 +02:00
|
|
|
var val time.Time
|
|
|
|
should.Nil(jsoniter.Unmarshal(output, &val))
|
|
|
|
should.Equal(int64(1000001000), val.UnixNano())
|
2017-06-20 11:46:29 +02:00
|
|
|
}
|