Skip to content

Commit

Permalink
time: update TestSub to avoid future regressions
Browse files Browse the repository at this point in the history
CL 131196 optimized Time.Sub, but was reverted because
it incorrectly computed the nanoseconds in some edge cases.
This CL adds a test case to enforce the correct behavior
so that a future optimization does not break this again.

Updates golang#17858
Updates golang#33677

Change-Id: I596d8302ca6bf721cf7ca11cc6f939639fcbdd43
Reviewed-on: https://go-review.googlesource.com/c/go/+/190524
Run-TryBot: Joe Tsai <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
Reviewed-by: Andrew Bonventre <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
  • Loading branch information
dsnet committed Aug 16, 2019
1 parent bb5441d commit c485506
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/time/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ var gobTests = []Time{
Date(0, 1, 2, 3, 4, 5, 6, UTC),
Date(7, 8, 9, 10, 11, 12, 13, FixedZone("", 0)),
Unix(81985467080890095, 0x76543210), // Time.sec: 0x0123456789ABCDEF
{}, // nil location
{}, // nil location
Date(1, 2, 3, 4, 5, 6, 7, FixedZone("", 32767*60)),
Date(1, 2, 3, 4, 5, 6, 7, FixedZone("", -32768*60)),
}
Expand Down Expand Up @@ -995,6 +995,7 @@ var subTests = []struct {
{Date(2300, 1, 1, 0, 0, 0, 0, UTC), Date(2000, 1, 1, 0, 0, 0, 0, UTC), Duration(maxDuration)},
{Date(2000, 1, 1, 0, 0, 0, 0, UTC), Date(2290, 1, 1, 0, 0, 0, 0, UTC), -290*365*24*Hour - 71*24*Hour},
{Date(2000, 1, 1, 0, 0, 0, 0, UTC), Date(2300, 1, 1, 0, 0, 0, 0, UTC), Duration(minDuration)},
{Date(2311, 11, 26, 02, 16, 47, 63535996, UTC), Date(2019, 8, 16, 2, 29, 30, 268436582, UTC), 9223372036795099414},
{MinMonoTime, MaxMonoTime, minDuration},
{MaxMonoTime, MinMonoTime, maxDuration},
}
Expand Down

0 comments on commit c485506

Please sign in to comment.