[Python-Dev] Status on PEP-431 Timezones

Lennart Regebro regebro at gmail.com
Tue Apr 14 21:04:48 CEST 2015


OK, so I realized another thing today, and that is that arithmetic
doesn't necessarily round trip.

For example, 2002-10-27 01:00 US/Eastern comes both in DST and STD.

But 2002-10-27 01:00 US/Eastern STD minus two days is 2002-10-25 01:00
US/Eastern DST
However, 2002-10-25 01:00 US/Eastern DST plus two days is 2002-10-27
01:00 US/Eastern, but it is ambiguous if you want DST or not DST.
And you can't pass in a is_dst flag to __add__, so the arithmatic must
just pick one, and the sensible one is to keep to the same DST.

That means that:

tz = get_timezone('US/Eastern')
dt = datetime(2002, 10, 27, 1, 0, tz=tz, is_dst=False)
dt2 = dt - 420 + 420
assert dt == dt2

Will fail, which will be unexpected for most people.

I think there is no way around this, but I thought I should flag for
it. This is a good reason to do all your date time arithmetic in UTC.

//Lennart


More information about the Python-Dev mailing list