[Python-checkins] r81989 - python/branches/py3k/Lib/calendar.py

alexander.belopolsky python-checkins at python.org
Mon Jun 14 20:33:19 CEST 2010


Author: alexander.belopolsky
Date: Mon Jun 14 20:33:19 2010
New Revision: 81989

Log:
Undo r81988 code change leaving added test.

Modified:
   python/branches/py3k/Lib/calendar.py

Modified: python/branches/py3k/Lib/calendar.py
==============================================================================
--- python/branches/py3k/Lib/calendar.py	(original)
+++ python/branches/py3k/Lib/calendar.py	Mon Jun 14 20:33:19 2010
@@ -587,12 +587,17 @@
 
 
 EPOCH = 1970
-_EPOCH_DATETIME = datetime.datetime(EPOCH, 1, 1)
-_SECOND = datetime.timedelta(seconds=1)
+_EPOCH_ORD = datetime.date(EPOCH, 1, 1).toordinal()
+
 
 def timegm(tuple):
     """Unrelated but handy function to calculate Unix timestamp from GMT."""
-    return (datetime.datetime(*tuple[:6]) - _EPOCH_DATETIME) // _SECOND
+    year, month, day, hour, minute, second = tuple[:6]
+    days = datetime.date(year, month, 1).toordinal() - _EPOCH_ORD + day - 1
+    hours = days*24 + hour
+    minutes = hours*60 + minute
+    seconds = minutes*60 + second
+    return seconds
 
 
 def main(args):


More information about the Python-checkins mailing list