File: time_as_int64_codec_test.go

package info (click to toggle)
golang-github-json-iterator-go 1.1.12-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 916 kB
  • sloc: sh: 19; makefile: 3
file content (31 lines) | stat: -rw-r--r-- 857 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package extra

import (
	"github.com/json-iterator/go"
	"github.com/stretchr/testify/require"
	"testing"
	"time"
)

func Test_time_as_int64(t *testing.T) {
	should := require.New(t)
	RegisterTimeAsInt64Codec(time.Nanosecond)
	output, err := jsoniter.Marshal(time.Unix(1497952257, 1002))
	should.Nil(err)
	should.Equal("1497952257000001002", string(output))
	var val time.Time
	should.Nil(jsoniter.Unmarshal(output, &val))
	should.Equal(int64(1497952257000001002), val.UnixNano())
}

func Test_time_as_int64_keep_microsecond(t *testing.T) {
	t.Skip("conflict")
	should := require.New(t)
	RegisterTimeAsInt64Codec(time.Microsecond)
	output, err := jsoniter.Marshal(time.Unix(1, 1002))
	should.Nil(err)
	should.Equal("1000001", string(output))
	var val time.Time
	should.Nil(jsoniter.Unmarshal(output, &val))
	should.Equal(int64(1000001000), val.UnixNano())
}