[Python-Dev] Status on PEP-431 Timezones

Tim Peters tim.peters at gmail.com
Mon Jul 27 20:49:32 CEST 2015


[Ronald Oussoren <ronaldoussoren at mac.com>]
> IMHO “+ 1 days” and “+ 24 hours” are two different things.
> Date arithmetic is full of messy things like that.

But it's a fact that they _are_ the same in naive time, which Python's
datetime single-timezone arithmetic implements:

- A minute is exactly 60 seconds.
- An hour is exactly 60 minutes.
- A day is exactly 24 hours.
- A week is exactly 7 days.

No context is necessary:  those are always true in naive time, and
that lack of mess is "a feature" to those who accept it for what it
is.

> “+ 1 month” is another example of that (which the datetime
> module punts completely and can be a source of endless
> bikeshidding).

Note that the only units timedelta accepts have clear (utterly
inarguable) meanings in naive time.  That's intentional too.  For
example, "a month" and "a year" have no clear meanings (as durations)
in naive time, so timedelta doesn't even pretend to support them.
Despite all appearance to the contrary in this thread, naive time is
bikeshed-free:  it's easy for someone to know all there is to know
about it by the time they're 12 ;-)

    datetime + timedelta(days=1)

is equivalent to

    datetime + timedelta(hours=24)

is equivalent to

    datetime + timedelta(minutes=60*24)

is equivalent to

    datetime + timedelta(seconds=60*60*24)

is equivalent to

    datetime + timedelta(microseconds=1000000*60*60*24)

Naive time is easy to understand, reason about, and work with.  When
it comes to the real world, political adjustments to and within time
zones can make the results dodgy, typically in the two DST-transition
hours per year when most people living in a given time zone are
sleeping.  How much complexity do you want to endure in case they wake
up? ;-)  Guido's answer was "none in arithmetic - push all the
complexity into conversions - then most uses can blissfully ignore the
complexities".

And note that because DST transitions "cancel out" over the span of a
year, the benefits and the few dodgy cases don't really change
regardless of whether you add one week or a hundred thousand weeks
(although there's no way to predict what governments will decide the
local clock "should say" a hundred thousand weeks from now - it's only
predictable in naive time).


More information about the Python-Dev mailing list