On Tue, Sep 22, 2015 at 3:01 AM, Nick Coghlan <ncoghlan@gmail.com> wrote:
... for times that
don't exist, "dt.astimezone(utc).astimezone(dt.tzinfo)" will normalise
them to be a time that actually exists in the original time zone, and
that normalisation also effectively happens when calling
"dt.timestamp()".
Yes. In fact, if you consider the canonical bijection between timestamps and datetimes (t = EPOCH + s * timedelta(0, 1); s = (t - EPOCH) / timedelta(0, 1)), t.astimezone(utc) and t.timestamp() become the same up to some annoying numerical details. The same logic applies to u.astimezone(tzinfo) and datetime.fromtimestamp(s). Note that I deliberately did not mark the units on the sketches: you can think of the UTC axis to be labeled by datetimes or by numeric timestamps.
Note that dt != dt.astimezone(utc).astimezone(dt.tzinfo) is one way to detect that dt is in a gap, but I recommend