Skip to content

Commit

Permalink
refact: simplify null-to-zero filling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ksw2000 committed Nov 30, 2024
1 parent 67a65f1 commit 025db2a
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions binding/form_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,13 @@ 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", "unixnano":
if val == "" {
val = "0"
}

tv, err := strconv.ParseInt(val, 10, 64)
if err != nil {
return err
Expand All @@ -418,11 +419,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
Expand Down

0 comments on commit 025db2a

Please sign in to comment.