diff options
author | Alexander Belopolsky <abalkin@users.noreply.github.com> | 2017-10-26 19:34:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-26 19:34:11 (GMT) |
commit | 66c88ce30ca2b23daa37038e1a3c0de98f241f50 (patch) | |
tree | 91e0dcb60059c3025fef3ea4e2dcb849f25b103f /Lib | |
parent | 52ad72dd0a5a56414cc29b7c9b03259169825f35 (diff) | |
download | cpython-66c88ce30ca2b23daa37038e1a3c0de98f241f50.zip cpython-66c88ce30ca2b23daa37038e1a3c0de98f241f50.tar.gz cpython-66c88ce30ca2b23daa37038e1a3c0de98f241f50.tar.bz2 |
Closes bpo-28281: Remove year (1-9999) limits on the weekday() function. (#4109)
Patch by Mark Gollahon.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/calendar.py | 5 | ||||
-rw-r--r-- | Lib/test/test_calendar.py | 62 |
2 files changed, 65 insertions, 2 deletions
diff --git a/Lib/calendar.py b/Lib/calendar.py index fb594e0..3828c43 100644 --- a/Lib/calendar.py +++ b/Lib/calendar.py @@ -111,8 +111,9 @@ def leapdays(y1, y2): def weekday(year, month, day): - """Return weekday (0-6 ~ Mon-Sun) for year (1970-...), month (1-12), - day (1-31).""" + """Return weekday (0-6 ~ Mon-Sun) for year, month (1-12), day (1-31).""" + if not datetime.MINYEAR <= year <= datetime.MAXYEAR: + year = 2000 + year % 400 return datetime.date(year, month, day).weekday() diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py index ad8b6bb..6241d11 100644 --- a/Lib/test/test_calendar.py +++ b/Lib/test/test_calendar.py @@ -9,6 +9,56 @@ import sys import datetime import os +# From https://en.wikipedia.org/wiki/Leap_year_starting_on_Saturday +result_0_02_text = """\ + February 0 +Mo Tu We Th Fr Sa Su + 1 2 3 4 5 6 + 7 8 9 10 11 12 13 +14 15 16 17 18 19 20 +21 22 23 24 25 26 27 +28 29 +""" + +result_0_text = """\ + 0 + + January February March +Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su + 1 2 1 2 3 4 5 6 1 2 3 4 5 + 3 4 5 6 7 8 9 7 8 9 10 11 12 13 6 7 8 9 10 11 12 +10 11 12 13 14 15 16 14 15 16 17 18 19 20 13 14 15 16 17 18 19 +17 18 19 20 21 22 23 21 22 23 24 25 26 27 20 21 22 23 24 25 26 +24 25 26 27 28 29 30 28 29 27 28 29 30 31 +31 + + April May June +Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su + 1 2 1 2 3 4 5 6 7 1 2 3 4 + 3 4 5 6 7 8 9 8 9 10 11 12 13 14 5 6 7 8 9 10 11 +10 11 12 13 14 15 16 15 16 17 18 19 20 21 12 13 14 15 16 17 18 +17 18 19 20 21 22 23 22 23 24 25 26 27 28 19 20 21 22 23 24 25 +24 25 26 27 28 29 30 29 30 31 26 27 28 29 30 + + July August September +Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su + 1 2 1 2 3 4 5 6 1 2 3 + 3 4 5 6 7 8 9 7 8 9 10 11 12 13 4 5 6 7 8 9 10 +10 11 12 13 14 15 16 14 15 16 17 18 19 20 11 12 13 14 15 16 17 +17 18 19 20 21 22 23 21 22 23 24 25 26 27 18 19 20 21 22 23 24 +24 25 26 27 28 29 30 28 29 30 31 25 26 27 28 29 30 +31 + + October November December +Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su + 1 1 2 3 4 5 1 2 3 + 2 3 4 5 6 7 8 6 7 8 9 10 11 12 4 5 6 7 8 9 10 + 9 10 11 12 13 14 15 13 14 15 16 17 18 19 11 12 13 14 15 16 17 +16 17 18 19 20 21 22 20 21 22 23 24 25 26 18 19 20 21 22 23 24 +23 24 25 26 27 28 29 27 28 29 30 25 26 27 28 29 30 31 +30 31 +""" + result_2004_01_text = """\ January 2004 Mo Tu We Th Fr Sa Su @@ -343,12 +393,20 @@ class OutputTestCase(unittest.TestCase): self.normalize_calendar(calendar.calendar(2004)), self.normalize_calendar(result_2004_text) ) + self.assertEqual( + self.normalize_calendar(calendar.calendar(0)), + self.normalize_calendar(result_0_text) + ) def test_output_textcalendar(self): self.assertEqual( calendar.TextCalendar().formatyear(2004), result_2004_text ) + self.assertEqual( + calendar.TextCalendar().formatyear(0), + result_0_text + ) def test_output_htmlcalendar_encoding_ascii(self): self.check_htmlcalendar_encoding('ascii', 'ascii') @@ -393,6 +451,10 @@ class OutputTestCase(unittest.TestCase): calendar.TextCalendar().formatmonth(2004, 1), result_2004_01_text ) + self.assertEqual( + calendar.TextCalendar().formatmonth(0, 2), + result_0_02_text + ) def test_formatmonthname_with_year(self): self.assertEqual( |