[issue23574] datetime: support leap seconds

Marc-Andre Lemburg report at bugs.python.org
Wed May 27 11:12:20 CEST 2015


Marc-Andre Lemburg added the comment:

Here's what mxDateTime uses:

>>> import mx.DateTime
>>>
>>> t1 = mx.DateTime.DateTime(2012,6,30,23,59,60)
>>> t2 = mx.DateTime.DateTime(2012,7,1,0,0,0)
>>>
>>> t1
<mx.DateTime.DateTime object for '2012-06-30 23:59:60.00' at 7fbb36008d68>
>>> t2
<mx.DateTime.DateTime object for '2012-07-01 00:00:00.00' at 7fbb36008d20>
>>>
>>> t2-t1
<mx.DateTime.DateTimeDelta object for '00:00:00.00' at 7fbb35ff0540>
>>> (t2-t1).seconds
0.0
>>>
>>> t1 + mx.DateTime.oneSecond
<mx.DateTime.DateTime object for '2012-07-01 00:00:01.00' at 7fbb360083d8>

It preserves the broken down values, but uses POSIX days of 86400 seconds per day to calculate time deltas.

It's a compromise, not a perfect solution, but it prevents applications from failing for that one second every now and then.

I don't believe there is a perfect solution, since what your application or users expect may well be different. All I can say is that raising exceptions in these rare cases is not what your users typically want :-)

----------
nosy: +lemburg

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23574>
_______________________________________


More information about the Python-bugs-list mailing list