You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can't round-trip datetimes<->timestamps prior to 1970 on Windows #46746
# If you run the code below on Py30a3 you get the output shown at the endimportcalendar, datetime, timepastdate=datetime.datetime(1969, 12, 31)
print(pastdate)
timestamp=calendar.timegm(pastdate.utctimetuple())
print(timestamp)
try:
pastdate_x=datetime.datetime.utcfromtimestamp(timestamp)
exceptValueErroraserr:
print("FAIL", err)
try:
print(time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(timestamp)))
exceptValueErroraserr:
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
If you doesn't care to the time zone (UTC), use:
>>> datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=-86400)
datetime.datetime(1969, 12, 31, 0, 0)
Activity
mark-summerfield commentedon Mar 27, 2008
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
tiran commentedon Mar 27, 2008
It's most likely a platform limitation. Some platforms doen't support
negative time stamps.
vstinner commentedon Nov 11, 2008
This code is portable on Windows, Linux but also works with
IronPython:
http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=7269
bitdancer commentedon Dec 22, 2010
Indeed, the time module is documented as not handling timestamps before the epoch.