Skip to content

Commit

Permalink
test: add test for zeroUnixNanoTime
Browse files Browse the repository at this point in the history
  • Loading branch information
ksw2000 committed Nov 30, 2024
1 parent 025db2a commit f4f5c44
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions binding/form_mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,25 +183,27 @@ func TestMapFormWithTag(t *testing.T) {

func TestMappingTime(t *testing.T) {
var s struct {
Time time.Time
LocalTime time.Time `time_format:"2006-01-02"`
ZeroValue time.Time
ZeroUnixTime time.Time `time_format:"unix"` // see issue #4098
CSTTime time.Time `time_format:"2006-01-02" time_location:"Asia/Shanghai"`
UTCTime time.Time `time_format:"2006-01-02" time_utc:"1"`
Time time.Time
LocalTime time.Time `time_format:"2006-01-02"`
ZeroValue time.Time
ZeroUnixTime time.Time `time_format:"unix"`
ZeroUnixNanoTime time.Time `time_format:"unixnano"`
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
time.Local, err = time.LoadLocation("Europe/Berlin")
require.NoError(t, err)

err = mapForm(&s, map[string][]string{
"Time": {"2019-01-20T16:02:58Z"},
"LocalTime": {"2019-01-20"},
"ZeroValue": {},
"ZeroUnixTime": {},
"CSTTime": {"2019-01-20"},
"UTCTime": {"2019-01-20"},
"Time": {"2019-01-20T16:02:58Z"},
"LocalTime": {"2019-01-20"},
"ZeroValue": {},
"ZeroUnixTime": {},
"ZeroUnixNanoTime": {},
"CSTTime": {"2019-01-20"},
"UTCTime": {"2019-01-20"},
})
require.NoError(t, err)

Expand All @@ -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, "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.ZeroUnixNanoTime.UTC().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-20 00:00:00 +0000 UTC", s.UTCTime.String())
Expand Down

0 comments on commit f4f5c44

Please sign in to comment.