[Datetime-SIG] DST explained visually

Guido van Rossum guido at python.org
Wed Aug 26 21:00:59 CEST 2015

```I've drawn a simple diagram showing the relationship between UTC and local
time throughout a DST cycle:

https://www.dropbox.com/s/ptx58d9zkd7m4vj/2015-08-26%2010.28.38.jpg?dl=0

tl;dr: Timeline arithmetic moves along the X axis (UTC); classic arithmetic
moves along the Y axis (local time).

Discussion:

On the X axis I've drawn UTC. On the Y axis I've drawn local time.

Ignoring most of the interesting bits, we observe that the mapping from UTC
to local time is a function -- for each UTC value there is exactly one
correct answer to the question "what is the local time". If we didn't have
DST, the plot would be a single straight line at an angle of 45 degrees,
i.e. the identity function (y = x). Regardless of the exact function,
mapping from local time back to UTC is done by looking up the local time on
the Y axis, going right parallel to the X axis until you hit a point on the
graph, and then going down to the X axis. What you find there will be UTC.
The interesting (and confusing) part is that with DST (or other changes
that move local time back) *the inverse is no longer a function*. Let's
look at DST in detail.

There are four interesting points along the X (UTC) axis: A, B, C, D. I've
also drawn four interesting points along the Y (local time) axis: P, Q, R,
S.

For simplicity, I am assuming DST moves the clock forward by one hour.
However, as the diagram is not labeled in absolute units, the individual
transitions can also be used to discuss other transitions (e.g. the areas
around A could be used to discuss a non-DST-related timezone adjustment, or
C-D could represent a leap second).

Points along the UTC (X) axis:

(A) Start of DST; local clock is move one hour forward. This moves local
time from P to Q.

(B) One hour before the end of DST. This is the beginning of a period in
UTC where mapping to local time and back can cause ambiguities. Note that
the period A-B is in reality several months (e.g. from some time in March
or April till some time in October or November, in the northern hemisphere).

(C) End of DST; local clock is moved one hour back, moving local time from
S to R (!).

(D) One hour after the end of DST. This is the end of the UTC period where
ambiguous local times matter.

Points along the local time (Y) axis:

(P) Local standard time when DST starts; local clock moves one hour
forward, from P to Q in an instant.

(Q) Local daylight saving time at the start of DST.

(R) Start of ambiguous local time.

(S) End of ambiguous local time. The first time we hit this point we move
the local clock back by one hour (to R). The second time we hit this point
we do nothing.

The proposal in PEP 495 adds a 'fold' flag whose value is 0 *except* for
local times mapped from UTC period C-D; between C and D local time is
between R and S with fold=1. (Note that the current text of the PEP has a
flag named 'first' whose definition is the opposite; but the plan is to
switch to fold=0. In any case it's one bit of information and it's only
used for times between P-Q.)

It may not be obvious from the diagram, but by taking the fold flag and the
rest of the local time together, the mapping from local time (augmented
with the fold flag) to UTC is once again a function, at least in the domain
R-S (the fold). In the gap (P-Q) the inverse has no value; but PEP 495
extends the meaning of the fold flag to assign a meaning here too, by
mapping P-Q with fold=0 to the extension (up and to the right) of the plot
of standard time, and P-Q with fold=1 to the extension (down and to the
left) of the plot of DST. (The diagram doesn't label the relevant points
but there are dotted lines representing these extensions).

My final observation is that the distinction between classic and timeline
arithmetic is simply the distinction between the two axes of the plot:
timeline==X, classic==Y. Both are useful in different contexts.

--
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/datetime-sig/attachments/20150826/0b8792ee/attachment.html>
```