Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use math.Round #113

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading