mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
#15421: fix an OverflowError in Calendar.itermonthdates() after datetime.MAXYEAR. Patch by Cédric Krier.
This commit is contained in:
parent
003014bf1e
commit
cadff70ba5
3 changed files with 14 additions and 1 deletions
|
@ -161,7 +161,11 @@ class Calendar(object):
|
||||||
oneday = datetime.timedelta(days=1)
|
oneday = datetime.timedelta(days=1)
|
||||||
while True:
|
while True:
|
||||||
yield date
|
yield date
|
||||||
|
try:
|
||||||
date += oneday
|
date += oneday
|
||||||
|
except OverflowError:
|
||||||
|
# Adding one day could fail after datetime.MAXYEAR
|
||||||
|
break
|
||||||
if date.month != month and date.weekday() == self.firstweekday:
|
if date.month != month and date.weekday() == self.firstweekday:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ import unittest
|
||||||
|
|
||||||
from test import test_support
|
from test import test_support
|
||||||
import locale
|
import locale
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
|
||||||
result_2004_text = """
|
result_2004_text = """
|
||||||
|
@ -262,6 +263,11 @@ class CalendarTestCase(unittest.TestCase):
|
||||||
new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
|
new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
|
||||||
self.assertEquals(old_october, new_october)
|
self.assertEquals(old_october, new_october)
|
||||||
|
|
||||||
|
def test_itermonthdates(self):
|
||||||
|
# ensure itermonthdates doesn't overflow after datetime.MAXYEAR
|
||||||
|
# see #15421
|
||||||
|
list(calendar.Calendar().itermonthdates(datetime.MAXYEAR, 12))
|
||||||
|
|
||||||
|
|
||||||
class MonthCalendarTestCase(unittest.TestCase):
|
class MonthCalendarTestCase(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
|
@ -103,6 +103,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #15421: fix an OverflowError in Calendar.itermonthdates() after
|
||||||
|
datetime.MAXYEAR. Patch by Cédric Krier.
|
||||||
|
|
||||||
- Issue #15970: xml.etree.ElementTree now serializes correctly the empty HTML
|
- Issue #15970: xml.etree.ElementTree now serializes correctly the empty HTML
|
||||||
elements 'meta' and 'param'.
|
elements 'meta' and 'param'.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue