test: add test for zeroUnixNanoTime

This commit is contained in:
Kashiwa 2024-11-30 06:39:22 +00:00
parent 025db2a7c9
commit f4f5c44402

View File

@ -183,12 +183,13 @@ func TestMapFormWithTag(t *testing.T) {
func TestMappingTime(t *testing.T) { func TestMappingTime(t *testing.T) {
var s struct { var s struct {
Time time.Time Time time.Time
LocalTime time.Time `time_format:"2006-01-02"` LocalTime time.Time `time_format:"2006-01-02"`
ZeroValue time.Time ZeroValue time.Time
ZeroUnixTime time.Time `time_format:"unix"` // see issue #4098 ZeroUnixTime time.Time `time_format:"unix"`
CSTTime time.Time `time_format:"2006-01-02" time_location:"Asia/Shanghai"` ZeroUnixNanoTime time.Time `time_format:"unixnano"`
UTCTime time.Time `time_format:"2006-01-02" time_utc:"1"` CSTTime time.Time `time_format:"2006-01-02" time_location:"Asia/Shanghai"`
UTCTime time.Time `time_format:"2006-01-02" time_utc:"1"`
} }
var err error var err error
@ -196,12 +197,13 @@ func TestMappingTime(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
err = mapForm(&s, map[string][]string{ err = mapForm(&s, map[string][]string{
"Time": {"2019-01-20T16:02:58Z"}, "Time": {"2019-01-20T16:02:58Z"},
"LocalTime": {"2019-01-20"}, "LocalTime": {"2019-01-20"},
"ZeroValue": {}, "ZeroValue": {},
"ZeroUnixTime": {}, "ZeroUnixTime": {},
"CSTTime": {"2019-01-20"}, "ZeroUnixNanoTime": {},
"UTCTime": {"2019-01-20"}, "CSTTime": {"2019-01-20"},
"UTCTime": {"2019-01-20"},
}) })
require.NoError(t, err) require.NoError(t, err)
@ -210,6 +212,7 @@ func TestMappingTime(t *testing.T) {
assert.Equal(t, "2019-01-19 23:00:00 +0000 UTC", s.LocalTime.UTC().String()) assert.Equal(t, "2019-01-19 23:00:00 +0000 UTC", s.LocalTime.UTC().String())
assert.Equal(t, "0001-01-01 00:00:00 +0000 UTC", s.ZeroValue.String()) assert.Equal(t, "0001-01-01 00:00:00 +0000 UTC", s.ZeroValue.String())
assert.Equal(t, "1970-01-01 00:00:00 +0000 UTC", s.ZeroUnixTime.UTC().String()) assert.Equal(t, "1970-01-01 00:00:00 +0000 UTC", s.ZeroUnixTime.UTC().String())
assert.Equal(t, "1970-01-01 00:00:00 +0000 UTC", s.ZeroUnixNanoTime.UTC().String())
assert.Equal(t, "2019-01-20 00:00:00 +0800 CST", s.CSTTime.String()) assert.Equal(t, "2019-01-20 00:00:00 +0800 CST", s.CSTTime.String())
assert.Equal(t, "2019-01-19 16:00:00 +0000 UTC", s.CSTTime.UTC().String()) assert.Equal(t, "2019-01-19 16:00:00 +0000 UTC", s.CSTTime.UTC().String())
assert.Equal(t, "2019-01-20 00:00:00 +0000 UTC", s.UTCTime.String()) assert.Equal(t, "2019-01-20 00:00:00 +0000 UTC", s.UTCTime.String())