summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1999-06-09 15:07:38 (GMT)
committerGuido van Rossum <guido@python.org>1999-06-09 15:07:38 (GMT)
commitb39aff87f7b69a6c434d538808e4ebc015754a6f (patch)
tree8953df51c97bb511690c7e8919855ad2cc1a0a1d
parent145a5f73f0064b3779e3f0a592112615a6d0fb5d (diff)
downloadcpython-b39aff87f7b69a6c434d538808e4ebc015754a6f.zip
cpython-b39aff87f7b69a6c434d538808e4ebc015754a6f.tar.gz
cpython-b39aff87f7b69a6c434d538808e4ebc015754a6f.tar.bz2
Add unrelated but handy function: timegm(), to calculate Unix
timestamp from GMT tuple.
-rw-r--r--Lib/calendar.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/calendar.py b/Lib/calendar.py
index 8d5681a..c9bc497 100644
--- a/Lib/calendar.py
+++ b/Lib/calendar.py
@@ -151,3 +151,20 @@ def prcal(year):
prweek(cal[i], 2)
print _spacing,
print
+
+# Unrelated but handy function to calculate Unix timestamp from GMT
+EPOCH = 1970
+def timegm(tuple):
+ year, month, day, hour, minute, second = tuple[:6]
+ assert year >= EPOCH
+ assert 1 <= month <= 12
+ days = 365*(year-EPOCH) + leapdays(EPOCH, year)
+ for i in range(1, month):
+ days = days + mdays[i]
+ if month > 2 and isleap(year):
+ days = days + 1
+ days = days + day - 1
+ hours = days*24 + hour
+ minutes = hours*60 + minute
+ seconds = minutes*60 + second
+ return seconds