Skip to content

Commit

Permalink
use math.Round (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
icholy authored Jul 15, 2024
1 parent 65fb477 commit 5969ead
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,18 +345,7 @@ func ParseTime(s string) (Time, error) {
minute, _ := strconv.Atoi(s[2:4])
second, _ := strconv.ParseFloat(s[4:], 64)
whole, frac := math.Modf(second)
return Time{true, hour, minute, int(whole), int(round(frac * 1000))}, nil
}

// round is implemented here because it wasn't added until go1.10
// this code is taken directly from the math.Round documentation
// TODO: use math.Round after a reasonable amount of time
func round(x float64) float64 {
t := math.Trunc(x)
if math.Abs(x-t) >= 0.5 {
return t + math.Copysign(1, x)
}
return t
return Time{true, hour, minute, int(whole), int(math.Round(frac * 1000))}, nil
}

// Date type
Expand Down

0 comments on commit 5969ead

Please sign in to comment.