Skip to content

Commit 97c1bfb

Browse files
committed
add gmtime pre-epoch test
1 parent d58444c commit 97c1bfb

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Lib/test/test_time.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,24 @@ def test_epoch(self):
187187
# Only test the date and time, ignore other gmtime() members
188188
self.assertEqual(tuple(epoch)[:6], (1970, 1, 1, 0, 0, 0), epoch)
189189

190+
def test_gmtime(self):
191+
# expected format:
192+
# (tm_year, tm_mon, tm_mday,
193+
# tm_hour, tm_min, tm_sec,
194+
# tm_wday, tm_yday)
195+
for t, expected in (
196+
(-13262400, (1969, 7, 31, 12, 0, 0, 3, 212)),
197+
(-6177600, (1969, 10, 21, 12, 0, 0, 1, 294)),
198+
# non-leap years (pre epoch)
199+
(-2203891200, (1900, 3, 1, 0, 0, 0, 3, 60)),
200+
(-5359564800, (1800, 3, 1, 0, 0, 0, 3, 60)),
201+
# leap years (pre epoch)
202+
(-2077660800, (1904, 3, 1, 0, 0, 0, 3, 61)),
203+
):
204+
with self.subTest(t=t, expected=expected):
205+
res = time.gmtime(t)
206+
self.assertEqual(tuple(res)[:8], expected, res)
207+
190208
def test_strftime(self):
191209
tt = time.gmtime(self.t)
192210
for directive in ('a', 'A', 'b', 'B', 'c', 'd', 'H', 'I',

0 commit comments

Comments
 (0)