fix(time): binding time with empty value (#4103)

* fix: binding time with empty value (#4098)

* refact: simplify null-to-zero filling logic

* test: add test for zeroUnixNanoTime
This commit is contained in:
Kashiwa
2025-05-21 19:21:46 +08:00
committed by GitHub
parent 8f7c340577
commit 674522db91
2 changed files with 21 additions and 15 deletions
+5 -5
View File
@@ -397,6 +397,11 @@ func setTimeField(val string, structField reflect.StructField, value reflect.Val
timeFormat = time.RFC3339
}
if val == "" {
value.Set(reflect.ValueOf(time.Time{}))
return nil
}
switch tf := strings.ToLower(timeFormat); tf {
case "unix", "unixmilli", "unixmicro", "unixnano":
tv, err := strconv.ParseInt(val, 10, 64)
@@ -420,11 +425,6 @@ func setTimeField(val string, structField reflect.StructField, value reflect.Val
return nil
}
if val == "" {
value.Set(reflect.ValueOf(time.Time{}))
return nil
}
l := time.Local
if isUTC, _ := strconv.ParseBool(structField.Tag.Get("time_utc")); isUTC {
l = time.UTC