aboutsummaryrefslogtreecommitdiff
path: root/src/time/time_test.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2017-03-31 12:34:25 -0400
committerRuss Cox <rsc@golang.org>2017-03-31 20:39:58 +0000
commit105cc2bd6396f47bc613721fb6c1db66050e15ab (patch)
tree3d7b195c7b5df39925dfd1702b7e30a8b4bf943c /src/time/time_test.go
parent8ab71304d4f02e4280eb5c04422cdec5feb27c11 (diff)
downloadgo-105cc2bd6396f47bc613721fb6c1db66050e15ab.tar.gz
go-105cc2bd6396f47bc613721fb6c1db66050e15ab.zip
time: test and fix Time.Round, Duration.Round for d > 2⁶²
Round uses r+r < d to decide whether the remainder is above or below half of d (to decide whether to round up or down). This is wrong when r+r wraps negative, because it looks < d but is really > d. No one will ever care about rounding to a multiple of d > 2⁶² (about 146 years), but might as well get it right. Fixes #19807. Change-Id: I1b55a742dc36e02a7465bc778bf5dd74fe71f7c0 Reviewed-on: https://go-review.googlesource.com/39151 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/time/time_test.go')
-rw-r--r--src/time/time_test.go2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/time/time_test.go b/src/time/time_test.go
index ebe28e61f4..dba8e0dadc 100644
--- a/src/time/time_test.go
+++ b/src/time/time_test.go
@@ -233,6 +233,7 @@ var truncateRoundTests = []struct {
{Date(-1, January, 1, 12, 15, 31, 5e8, UTC), 3},
{Date(2012, January, 1, 12, 15, 30, 5e8, UTC), Second},
{Date(2012, January, 1, 12, 15, 31, 5e8, UTC), Second},
+ {Unix(-19012425939, 649146258), 7435029458905025217}, // 5.8*d rounds to 6*d, but .8*d+.8*d < 0 < d
}
func TestTruncateRound(t *testing.T) {
@@ -1107,6 +1108,7 @@ var durationRoundTests = []struct {
{9e18, 5e18, 1<<63 - 1},
{-8e18, 3e18, -9e18},
{-9e18, 5e18, -1 << 63},
+ {3<<61 - 1, 3 << 61, 3 << 61},
}
func TestDurationRound(t *testing.T) {