[Datetime-SIG] Another round on error-checking

Alexander Belopolsky alexander.belopolsky at gmail.com
Tue Sep 1 21:50:41 CEST 2015

On Tue, Sep 1, 2015 at 2:00 PM, Alexander Belopolsky <
alexander.belopolsky at gmail.com> wrote:

> And there's also that, after
>>     d = dt1 - dt2
>> I suspect it may no longer always be the case that
>>     dt1 == dt2 + d
>> (unsure, but can't make time for it now)
> That's the price we pay for classic arithmetic anyways.

Let me clarify what I mean by that:

>>> from datetime import *
>>> exec(open("Doc/includes/tzinfo-examples.py").read())
>>> t1 = datetime(2015, 10, 31, 12, tzinfo=Eastern)
>>> t2 = datetime(2015, 11, 1, 12, tzinfo=Eastern)
>>> u = datetime(2000, 1, 1, tzinfo=timezone.utc)
>>> (t1 - u) - (t2 - u) == t2 - t1

This is a fundamental property of classic arithmetic and the only way to
prevent something like this from happening is (as Guido mentioned
previously) to disallow cross-zone arithmetic.  This would be quite
justifiable from the relativity POV: whether or not two events occur
simultaneously at two different places depends on the speed of the
observer.   This fact will be important when ordinary computers get clocks
with nanosecond precision.  Meanwhile, our governments let us enjoy the
effects relativity and time travel twice a year at pedestrian speeds: if
you add a day in New York, go to Paris, subtract a day there and come back
to New York you may not find yourself at the same time.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/datetime-sig/attachments/20150901/08315b3e/attachment.html>

More information about the Datetime-SIG mailing list