From 5969eade781a950a9f7021e2ffe4ea8b2bdb7392 Mon Sep 17 00:00:00 2001 From: Ilia Choly Date: Mon, 15 Jul 2024 16:04:35 -0400 Subject: [PATCH] use math.Round (#113) --- types.go | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/types.go b/types.go index e161b7f..7d04dd2 100644 --- a/types.go +++ b/types.go @@ -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