STINNER Victor added the comment:

Ignoring leap seconds introduces unexpected result.

datetime.timestamp -> datetime.fromtimestamp drops one second:

$ ./python
Python 3.5.0a1+ (default:760f222103c7+, Mar  3 2015, 15:36:36) 
>>> t=datetime.datetime(2012, 6, 30, 23, 59, 60).timestamp()
>>> datetime.datetime.fromtimestamp(t)
datetime.datetime(2012, 6, 30, 23, 59, 59)

time and datetime modules behave differently:

$ ./python
Python 3.5.0a1+ (default:760f222103c7+, Mar  3 2015, 15:36:36) 
>>> import datetime, time
>>> t1=datetime.datetime(2012, 6, 30, 23, 59, 59).timestamp()
>>> t2=datetime.datetime(2012, 6, 30, 23, 59, 60).timestamp()
>>> t2-t1
0.0

>>> t3=time.mktime((2012, 6, 30, 23, 59, 59, -1, -1, -1))
>>> t4=time.mktime((2012, 6, 30, 23, 59, 60, -1, -1, -1))
>>> t4-t3
1.0

>>> t1 == t2 == t3
True
>>> t3, t4
(1341093599.0, 1341093600.0)

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue23574>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to