Issue 6280: Tests and simpler implementation for calendar.timegm

This commit is contained in:
Alexander Belopolsky 2010-06-14 17:32:03 +00:00
parent 4e749a1113
commit 43ca710a44
2 changed files with 13 additions and 10 deletions

View file

@ -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):