From 17cdd96572c15975c88df58f599056c0dbea0d7b Mon Sep 17 00:00:00 2001 From: John Wang Date: Sat, 16 Sep 2023 18:15:11 -0700 Subject: [PATCH] style: `time/timeutil`: update conditionals --- time/timeutil/duration_info.go | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/time/timeutil/duration_info.go b/time/timeutil/duration_info.go index 894b5c9..c0b54f2 100644 --- a/time/timeutil/duration_info.go +++ b/time/timeutil/duration_info.go @@ -344,8 +344,7 @@ func parseDurationHours(d string) (time.Duration, error) { d = strings.TrimSpace(d) if d == "" || d == "0" { return 0, nil - } - if f, err := strconv.ParseFloat(d, 64); err != nil { + } else if f, err := strconv.ParseFloat(d, 64); err != nil { return 0, err } else { return time.Duration(int64(f * float64(NanosPerHour))), nil @@ -356,8 +355,7 @@ func parseDurationMinutes(d string) (time.Duration, error) { d = strings.TrimSpace(d) if d == "" || d == "0" { return 0, nil - } - if f, err := strconv.ParseFloat(d, 64); err != nil { + } else if f, err := strconv.ParseFloat(d, 64); err != nil { return 0, err } else { return time.Duration(int64(f * float64(NanosPerMinute))), nil @@ -368,8 +366,7 @@ func parseDurationSeconds(d string) (time.Duration, error) { d = strings.TrimSpace(d) if d == "" || d == "0" { return 0, nil - } - if f, err := strconv.ParseFloat(d, 64); err != nil { + } else if f, err := strconv.ParseFloat(d, 64); err != nil { return 0, err } else { return time.Duration(int64(f * float64(NanosPerSecond))), nil @@ -380,8 +377,7 @@ func parseDurationMilliseconds(d string) (time.Duration, error) { d = strings.TrimSpace(d) if d == "" || d == "0" { return 0, nil - } - if f, err := strconv.ParseFloat(d, 64); err != nil { + } else if f, err := strconv.ParseFloat(d, 64); err != nil { return 0, err } else { return time.Duration(int64(f * float64(NanosPerMillisecond))), nil @@ -392,8 +388,7 @@ func parseDurationMicroseconds(d string) (time.Duration, error) { d = strings.TrimSpace(d) if d == "" || d == "0" { return 0, nil - } - if f, err := strconv.ParseFloat(d, 64); err != nil { + } else if f, err := strconv.ParseFloat(d, 64); err != nil { return 0, err } else { return time.Duration(int64(f * float64(NanosPerMicrosecond))), nil @@ -404,8 +399,7 @@ func parseDurationNanoseconds(d string) (time.Duration, error) { d = strings.TrimSpace(d) if d == "" || d == "0" { return 0, nil - } - if f, err := strconv.ParseFloat(d, 64); err != nil { + } else if f, err := strconv.ParseFloat(d, 64); err != nil { return 0, err } else { return time.Duration(int64(f)), nil