[Datetime-SIG] PEP-0500 (Alternative datetime arithmetic) Was: PEP 495 ... is ready ...

Alexander Belopolsky alexander.belopolsky at gmail.com
Tue Aug 18 17:38:36 CEST 2015

On Tue, Aug 18, 2015 at 11:07 AM, Guido van Rossum <guido at python.org> wrote:
> PEP 500 allows way more freedom than is needed.

This is right.  With respect to finding elapsed time between two times
(x and y) expressed as datetime instances, PEP-0500 allow tzinfo
implementor to provide an arbitrary function of two variables: d(x,
y), while arguably in most cases d(x, y) = x - f(x) - y + f(y), where
f is a function of a single variable.  (In terms of current tzinfo
interface, f is the utcoffset() function.)  In other words, the PEP
allows arbitrary stretching and shrinking of the time line, while in
most use cases only cutting and shifting is needed.

However, I don't see this additional freedom as a big complication.
Even in the common case, it may be easier to implement d(x, y) than to
figure out f(x).  The problem with f(x) is that it is the UTC offset
as a function of local time while most TZ database interfaces only
provide UTC offset as a function of UTC time.  As a result, it is
often easier to implement d(x, y) (for example, as d(x, y) = g(x) -
g(y)) than to implement f(x).

More information about the Datetime-SIG mailing list