mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue 6280: Tests and simpler implementation for calendar.timegm
This commit is contained in:
parent
4e749a1113
commit
43ca710a44
2 changed files with 13 additions and 10 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue