[Python-bugs-list] [ python-Bugs-685011 ] calendar module overflow handling
SourceForge.net
noreply@sourceforge.net
Tue, 11 Feb 2003 16:54:23 -0800
Bugs item #685011, was opened at 2003-02-11 19:34
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=685011&group_id=5470
Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Richard Jones (richard)
>Assigned to: Raymond Hettinger (rhettinger)
Summary: calendar module overflow handling
Initial Comment:
The calendar module has lost a significant area of functionality in
Python 2.3
- that of handling overflows in the tuples passed to timegm().
Python 2.2.2 (#1, Oct 28 2002, 16:39:08)
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time,calendar
>>> time.gmtime(calendar.timegm((2003,1,30,0,0,0,0,0,0)))
(2003, 1, 30, 0, 0, 0, 3, 30, 0)
>>> time.gmtime(calendar.timegm((2003,2,30,0,0,0,0,0,0)))
(2003, 3, 2, 0, 0, 0, 6, 61, 0)
>>>
Python 2.3a1 (#1, Feb 6 2003, 14:54:16)
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time,calendar
>>> time.gmtime(calendar.timegm((2003,1,30,0,0,0,0,0,0)))
(2003, 1, 30, 0, 0, 0, 3, 30, 0)
>>> time.gmtime(calendar.timegm((2003,2,30,0,0,0,0,0,0)))
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.3/calendar.py", line 216, in timegm
days = datetime.date(year, month, day).toordinal() - _EPOCH_ORD
ValueError: day is out of range for month
>>>
Is this functionality likely to be reinstated for 2.3's release?
----------------------------------------------------------------------
>Comment By: Tim Peters (tim_one)
Date: 2003-02-11 19:54
Message:
Logged In: YES
user_id=31435
Cute. My best reading of the code is that you were relying
on an undocumented accident. The timegm code in 2.2 did
do bounds-checking on the year and month, it looks like it
was just too lazy to check the day.
Assigning to Raymond to teach him a lesson <wink>. If you
want to restore this accident, pass 1 instead of days to the
datetime constructor, and restore the old
days = days + day - 1
line after that returns. It should still be lot faster than the
2.2 code.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=685011&group_id=5470