refact: simplify null-to-zero filling logic

This commit is contained in:
Kashiwa 2024-11-30 06:36:38 +00:00
parent 67a65f1a5a
commit 025db2a7c9

View File

@ -397,12 +397,13 @@ func setTimeField(val string, structField reflect.StructField, value reflect.Val
timeFormat = time.RFC3339 timeFormat = time.RFC3339
} }
switch tf := strings.ToLower(timeFormat); tf {
case "unix", "unixnano":
if val == "" { if val == "" {
val = "0" value.Set(reflect.ValueOf(time.Time{}))
return nil
} }
switch tf := strings.ToLower(timeFormat); tf {
case "unix", "unixnano":
tv, err := strconv.ParseInt(val, 10, 64) tv, err := strconv.ParseInt(val, 10, 64)
if err != nil { if err != nil {
return err return err
@ -418,11 +419,6 @@ func setTimeField(val string, structField reflect.StructField, value reflect.Val
return nil return nil
} }
if val == "" {
value.Set(reflect.ValueOf(time.Time{}))
return nil
}
l := time.Local l := time.Local
if isUTC, _ := strconv.ParseBool(structField.Tag.Get("time_utc")); isUTC { if isUTC, _ := strconv.ParseBool(structField.Tag.Get("time_utc")); isUTC {
l = time.UTC l = time.UTC