]> granicus.if.org Git - python/commitdiff
SF 685011: calendar module overflow handling
authorRaymond Hettinger <python@rcn.com>
Thu, 13 Feb 2003 22:58:02 +0000 (22:58 +0000)
committerRaymond Hettinger <python@rcn.com>
Thu, 13 Feb 2003 22:58:02 +0000 (22:58 +0000)
Restored a Py2.2 behavior to not range check the day of the month.
A user application was this exploiting undocumented, accidental "feature".

Lib/calendar.py

index 365ca2634445ed855905d98fae31d3dfd0665297..fb56826f6fb62ffca73829fa93b01371443f7fcd 100644 (file)
@@ -213,7 +213,7 @@ _EPOCH_ORD = datetime.date(EPOCH, 1, 1).toordinal()
 def timegm(tuple):
     """Unrelated but handy function to calculate Unix timestamp from GMT."""
     year, month, day, hour, minute, second = tuple[:6]
-    days = datetime.date(year, month, day).toordinal() - _EPOCH_ORD
+    days = datetime.date(year, month, 1).toordinal() - _EPOCH_ORD + day - 1
     hours = days*24 + hour
     minutes = hours*60 + minute
     seconds = minutes*60 + second