[Datetime-SIG] Calendar vs timespan calculations...

Alexander Belopolsky alexander.belopolsky at gmail.com
Sun Aug 2 16:35:01 CEST 2015


On Sun, Aug 2, 2015 at 9:46 AM, Guido van Rossum <guido at python.org> wrote:
> There's a simpler reason for ignoring leap seconds in datetime: Python's
> wall clock is mappable to POSIX timestamps, which also ignore leap seconds
> (the reason being Tim's long explanation :-).

Note that if you combine several recently made proposals, you can have
a fully backward-compatible solution for leap seconds.   You can
simply use time(23, 59, ss, us, first=False) to stand for times in the
23:60 minute and delegate arithmetics to the tzinfo object:

def __add__(self, delta):
    try:
        add = self.tzinfo.add
    except AttributeError:
        # current logic
    else:
        return add(self, delta)

Same for `__sub__` and possibly `strftime`, `isoformat`, etc. if you
want time(23, 59, ss, us, first=False) to be printed as 23:60:ss.us.

Note that Olson database contains information about leap seconds, so
once you have access to that and a way to spell 23:60 (as the repeated
23:59!) you can easily implement "correct" UTC timezone.

On the other hand,  I would like to proceed in baby steps.  Let's
first implement the means to disambiguate repeated times and various
improvements that it will allow to the existing datetime
functionality.  Meanwhile the developers of timezone libraries will
hopefully embrace the new feature and improve their offerings.

Hopefully, by the time we are ready to distribute a full TZ database
with Python, the problem of distribution will be solved by IETF [1].
If their solution (as expected) includes leap second information, we
can find a way to give Python users access to it in one way or
another.

[1]: https://tools.ietf.org/html/draft-ietf-tzdist-service-11


More information about the Datetime-SIG mailing list