This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: overflow error in calendar module
Type: Stage:
Components: Windows Versions: Python 2.2
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: nnorwitz Nosy List: kibab, nnorwitz
Priority: normal Keywords:

Created on 2002-10-03 16:57 by kibab, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Messages (5)
msg12575 - (view) Author: Kaleb Pederson (kibab) Date: 2002-10-03 16:57
The calendar module doesn't explicitly say that it 
doesn't work for dates pre-1970.  The best case is that 
this is a DOCUMENTATION BUG.  I would prefer to see 
a more powerful date module that starts at the 
beginning of the Gregorian calendar.

What it does say:

From http://www.python.org/doc/current/lib/module-
calendar.html: (when 2.2.1 is current)

weekday(year, month, day)  - Returns the day of the 
week (0 is Monday) for year (1970-...), month (1-12), 
day (1-31).

// I figured that was fine, I can avoid using that function 
in my wrapper

timegm(tuple) - An unrelated but handy function that 
takes a time tuple such as returned by the gmtime() 
function in the time module, and returns the 
corresponding Unix timestamp value, assuming an 
epoch of 1970, and the POSIX encoding. In fact, 
time.gmtime() and timegm() are each others' inverse.

// Okay, I can avoid that too, especially since it 
is "unrelated"

I probably should have got a clue based on the above, 
but I didn't....

Here is the traceback:

(under python 2.2.1-Windows)
>>> import calendar
>>> calendar.monthcalendar(1969,12)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "c:\progra~1\python22\lib\calendar.py", line 122, 
in monthcalendar
    day1, ndays = monthrange(year, month)
  File "c:\progra~1\python22\lib\calendar.py", line 115, 
in monthrange
    day1 = weekday(year, month, 1)
  File "c:\progra~1\python22\lib\calendar.py", line 106, 
in weekday
    secs = mktime((year, month, day, 0, 0, 0, 0, 0, 0))
OverflowError: mktime argument out of range

The error is identical under Linux


There was one related "bug report" previously but 
nothing else identical:
[ 434143 ] calendar module broken for 1900
msg12576 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2002-11-02 02:53
Logged In: YES 
user_id=33168

Is this still a problem in 2.2.2?
msg12577 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2002-11-02 21:05
Logged In: YES 
user_id=33168

I can't replicate on Linux w/2.2.2 or 2.3, changing category
to Windows.
msg12578 - (view) Author: Kaleb Pederson (kibab) Date: 2002-11-02 22:04
Logged In: YES 
user_id=157918

I checked it out under Linux on 2.2.2 and this is what I found.  
  
>>> calendar.monthcalendar(1902,01)  
[[0, 0, 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, 30, 31, 0, 0]]  
>>> calendar.monthcalendar(1901,12)  
Traceback (most recent call last):  
  File "<stdin>", line 1, in ?  
  File "calendar.py", line 122, in monthcalendar  
    day1, ndays = monthrange(year, month)  
  File "calendar.py", line 115, in monthrange  
    day1 = weekday(year, month, 1)  
  File "calendar.py", line 106, in weekday  
    secs = mktime((year, month, day, 0, 0, 0, 0, 0, 0))  
OverflowError: mktime argument out of range  
>>> calendar.monthcalendar(2038,1)  
[[0, 0, 0, 0, 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, 30, 31]]  
>>> calendar.monthcalendar(2038,2)  
Traceback (most recent call last):  
  File "<stdin>", line 1, in ?  
  File "calendar.py", line 122, in monthcalendar  
    day1, ndays = monthrange(year, month)  
  File "calendar.py", line 115, in monthrange  
    day1 = weekday(year, month, 1)  
  File "calendar.py", line 106, in weekday  
    secs = mktime((year, month, day, 0, 0, 0, 0, 0, 0))  
OverflowError: mktime argument out of range  
  
I consider this much better than before.  
  
I would only recommend that the upper and lower bounds for valid limits be 
added to the documentation as it isn't stated anywhere in the docs. 
 
Thanks. 
  
msg12579 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2002-11-03 00:16
Logged In: YES 
user_id=33168

Checked in as: Doc/lib/libcalendar.tex 1.16 and 1.14.6.2
History
Date User Action Args
2022-04-10 16:05:43adminsetgithub: 37258
2002-10-03 16:57:47kibabcreate