summaryrefslogtreecommitdiffstats
path: root/Lib/calendar.py
diff options
context:
space:
mode:
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>2010-06-14 17:32:03 (GMT)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>2010-06-14 17:32:03 (GMT)
commit43ca710a440b02ee38d04e46cf744e1fb9a86634 (patch)
treed6301a4c58bc4109d34cd863b80253121c4c7ae4 /Lib/calendar.py
parent4e749a1113acb4affed27afda07e17d96945290b (diff)
downloadcpython-43ca710a440b02ee38d04e46cf744e1fb9a86634.zip
cpython-43ca710a440b02ee38d04e46cf744e1fb9a86634.tar.gz
cpython-43ca710a440b02ee38d04e46cf744e1fb9a86634.tar.bz2
Issue 6280: Tests and simpler implementation for calendar.timegm
Diffstat (limited to 'Lib/calendar.py')
-rw-r--r--Lib/calendar.py11
1 files changed, 3 insertions, 8 deletions
diff --git a/Lib/calendar.py b/Lib/calendar.py
index 0c1fdad..a82b21a 100644
--- a/Lib/calendar.py
+++ b/Lib/calendar.py
@@ -587,17 +587,12 @@ def formatstring(cols, colwidth=_colwidth, spacing=_spacing):
EPOCH = 1970
-_EPOCH_ORD = datetime.date(EPOCH, 1, 1).toordinal()
-
+_EPOCH_DATETIME = datetime.datetime(EPOCH, 1, 1)
+_SECOND = datetime.timedelta(seconds=1)
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, 1).toordinal() - _EPOCH_ORD + day - 1
- hours = days*24 + hour
- minutes = hours*60 + minute
- seconds = minutes*60 + second
- return seconds
+ return (datetime.datetime(*tuple[:6]) - _EPOCH_DATETIME) // _SECOND
def main(args):