1
0
mirror of https://github.com/golang/go synced 2024-11-19 16:24:45 -07:00

time: fix handling of Jan 1 1601, 1201, 801, ...

R=r
CC=hurtonm
https://golang.org/cl/164074
This commit is contained in:
Russ Cox 2009-12-01 23:38:06 -08:00
parent eb16346dac
commit 8d652ee8ce
2 changed files with 7 additions and 6 deletions

View File

@ -104,15 +104,15 @@ func SecondsToUTC(sec int64) *Time {
n := -day/daysPer400Years + 1;
year -= 400 * n;
day += daysPer400Years * n;
} else {
}
// Cut off 400 year cycles.
n := day / daysPer400Years;
year += 400 * n;
day -= daysPer400Years * n;
}
// Cut off 100-year cycles
n := day / daysPer100Years;
n = day / daysPer100Years;
year += 100 * n;
day -= daysPer100Years * n;

View File

@ -26,6 +26,7 @@ var utctests = []TimeTest{
TimeTest{0, Time{1970, 1, 1, 0, 0, 0, Thursday, 0, "UTC"}},
TimeTest{1221681866, Time{2008, 9, 17, 20, 4, 26, Wednesday, 0, "UTC"}},
TimeTest{-1221681866, Time{1931, 4, 16, 3, 55, 34, Thursday, 0, "UTC"}},
TimeTest{-11644473600, Time{1601, 1, 1, 0, 0, 0, Monday, 0, "UTC"}},
TimeTest{1e18, Time{31688740476, 10, 23, 1, 46, 40, Friday, 0, "UTC"}},
TimeTest{-1e18, Time{-31688736537, 3, 10, 22, 13, 20, Tuesday, 0, "UTC"}},
TimeTest{0x7fffffffffffffff, Time{292277026596, 12, 4, 15, 30, 7, Sunday, 0, "UTC"}},