[Python-Dev] PEP 495 accepted (original) (raw)

Alexander Belopolsky alexander.belopolsky at gmail.com
Tue Sep 22 16:45:55 CEST 2015


On Tue, Sep 22, 2015 at 3:01 AM, Nick Coghlan <ncoghlan at 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 (dt.replace(fold=0).utcoffset() > dt.replace(fold=1).utcoffset().) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20150922/d28e4e3d/attachment.html>



More information about the Python-Dev mailing list