Skip to content
Myr

Revert "fix(time): binding time with empty value (#4103)" (#4245)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This reverts commit 674522db91d637d179c16c372d87756ea26fa089.

authored by Bo-Yi Wu · committed by GitHub · parent 674522d · Browse files · 2 files+15 added−21 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+15 added−21 removed

  • other:+15 added−21 removed

2 files+15 added−21 removed

modified:binding/form_mapping_test.go+10 added-16 removed
181 unmodified lines
182}183184func TestMappingTime(t *testing.T) {185 var s struct {186 Time time.Time187 LocalTime time.Time `time_format:"2006-01-02"`188 ZeroValue time.Time189 ZeroUnixTime time.Time `time_format:"unix"`190 ZeroUnixNanoTime time.Time `time_format:"unixnano"`191 CSTTime time.Time `time_format:"2006-01-02" time_location:"Asia/Shanghai"`192 UTCTime time.Time `time_format:"2006-01-02" time_utc:"1"`186 Time time.Time187 LocalTime time.Time `time_format:"2006-01-02"`188 ZeroValue time.Time189 CSTTime time.Time `time_format:"2006-01-02" time_location:"Asia/Shanghai"`190 UTCTime time.Time `time_format:"2006-01-02" time_utc:"1"`191 }192193 var err error194 time.Local, err = time.LoadLocation("Europe/Berlin")195 require.NoError(t, err)196197 err = mapForm(&s, map[string][]string{200 "Time": {"2019-01-20T16:02:58Z"},201 "LocalTime": {"2019-01-20"},202 "ZeroValue": {},203 "ZeroUnixTime": {},204 "ZeroUnixNanoTime": {},205 "CSTTime": {"2019-01-20"},206 "UTCTime": {"2019-01-20"},198 "Time": {"2019-01-20T16:02:58Z"},199 "LocalTime": {"2019-01-20"},200 "ZeroValue": {},201 "CSTTime": {"2019-01-20"},202 "UTCTime": {"2019-01-20"},203 })204 require.NoError(t, err)205206 assert.Equal(t, "2019-01-20 16:02:58 +0000 UTC", s.Time.String())207 assert.Equal(t, "2019-01-20 00:00:00 +0100 CET", s.LocalTime.String())208 assert.Equal(t, "2019-01-19 23:00:00 +0000 UTC", s.LocalTime.UTC().String())209 assert.Equal(t, "0001-01-01 00:00:00 +0000 UTC", s.ZeroValue.String())214 assert.Equal(t, "1970-01-01 00:00:00 +0000 UTC", s.ZeroUnixTime.UTC().String())215 assert.Equal(t, "1970-01-01 00:00:00 +0000 UTC", s.ZeroUnixNanoTime.UTC().String())210 assert.Equal(t, "2019-01-20 00:00:00 +0800 CST", s.CSTTime.String())211 assert.Equal(t, "2019-01-19 16:00:00 +0000 UTC", s.CSTTime.UTC().String())212 assert.Equal(t, "2019-01-20 00:00:00 +0000 UTC", s.UTCTime.String())213
424 unmodified lines
modified:binding/form_mapping.go+5 added-5 removed
395 unmodified lines
396 if timeFormat == "" {397 timeFormat = time.RFC3339398 }399400 if val == "" {401 value.Set(reflect.ValueOf(time.Time{}))402 return nil403 }404400 switch tf := strings.ToLower(timeFormat); tf {401 case "unix", "unixmilli", "unixmicro", "unixnano":402 tv, err := strconv.ParseInt(val, 10, 64)403 if err != nil {
15 unmodified lines
419 value.Set(reflect.ValueOf(t))420 return nil421 }422423 if val == "" {424 value.Set(reflect.ValueOf(time.Time{}))425 return nil426 }427428 l := time.Local429 if isUTC, _ := strconv.ParseBool(structField.Tag.Get("time_utc")); isUTC {430 l = time.UTC431 }
77 unmodified lines