[New-bugs-announce] [issue2494] Can't round-trip datetimes<->timestamps prior to 1970 on Windows

Mark Summerfield report at bugs.python.org
Thu Mar 27 08:27:07 CET 2008


New submission from Mark Summerfield <mark at qtrac.eu>:

# If you run the code below on Py30a3 you get the output shown at the end
import calendar, datetime, time

pastdate = datetime.datetime(1969, 12, 31)
print(pastdate)
timestamp = calendar.timegm(pastdate.utctimetuple())
print(timestamp)
try:
    pastdate_x = datetime.datetime.utcfromtimestamp(timestamp)
except ValueError as err:
    print("FAIL", err)
try:
    print(time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(timestamp)))
except ValueError as err:
    print("FAIL", err)

r"""
Python 30a3

Windows output:

1969-12-31 00:00:00
-86400
FAIL timestamp out of range for platform localtime()/gmtime() function
FAIL (22, 'Invalid argument')

Linux output:
1969-12-31 00:00:00
-86400
1969-12-31T00:00:00
"""
# What this appears to show is that you can't round-trip between
datetimes and timestamps on Windows for dates prior to 1970

----------
components: Library (Lib)
messages: 64578
nosy: mark
severity: normal
status: open
title: Can't round-trip datetimes<->timestamps prior to 1970 on Windows
type: behavior
versions: Python 3.0

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2494>
__________________________________


More information about the New-bugs-announce mailing list