[Python-ideas] Happy leap second

Guido van Rossum guido at python.org
Sat Jun 30 16:57:50 CEST 2012


POSIX timestamps don't have leap seconds. Convince POSIX to change
that and Python will follow suit.

On Sat, Jun 30, 2012 at 7:23 AM, Alexander Belopolsky
<alexander.belopolsky at gmail.com> wrote:
> Even though many have hoped that the authorities would stop fiddling
> with our clocks, today a leap second will be inserted in UTC.
> Systems using Olson/IANA timezone database have a way to deal with
> this without adjusting their clocks, but few systems are configured
> that way:
>
> $ TZ=right/UTC date -d @1341100824
> Sat Jun 30 23:59:60 UTC 2012
>
> (1341100824 is the number of seconds since epoch including the leap seconds.)
>
> Python's time module works fine with the "right" timezones:
>
>>>> import time
>>>> print(time.strftime('%T', time.localtime(1341100824)))
> 23:59:60
>
> but the datetime module clips the leap second down to the previous second:
>
>>>> from datetime import datetime
>>>> from datetime import datetime
>>>> print(datetime.fromtimestamp(1341100824).strftime('%T'))
> 23:59:59
>>>> print datetime.fromtimestamp(1341100823).strftime('%T')
> 23:59:59
>
> BDFL has been resisting adding support for leap seconds to the
> datetime module [1], but as the clocks become more accurate and
> synchronization requirements become stricter, we may want to revisit
> this issue.
>
> [1] http://mail.python.org/pipermail/python-ideas/2010-June/007307.html
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas



-- 
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list