A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2015-September/141761.html below:

[Python-Dev] PEP 495 accepted

[Python-Dev] PEP 495 acceptedGuido van Rossum guido at python.org
Tue Sep 22 16:43:23 CEST 2015
On Tue, Sep 22, 2015 at 12:01 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:

> It turns out there's one aspect of the accepted proposal that I
> *think* I understand, but want to confirm: the datetime -> POSIX
> timestamp -> datetime roundtrip for missing times.
>
> If I'm reading the PEP correctly, the defined invariant for local
> times that actually exist is:
>
>     dt == datetime.fromtimestamp(dt.timestamp())
>

Yup, except for floating point errors! Those have been fixed, finally:
http://bugs.python.org/issue23517 is now closed (the fix didn't make 3.5.0;
it will be in 3.5.1 though).


> No confusion there for the unambiguous times, or for times in a fold.
> In the latter case, the timestamps produced match the points where the
> UTC times match the local times in the "In the Fold" UTC/local
> diagram.
>

And this is where the fold flag is essential for the roundtripping.


> The subtle part is the handling of the "timestamp()" method for the
> "missing" times where the given time doesn't actually correspond to a
> valid time in the applicable timezone (local time for a naive datetime
> object).
>
> Based on the UTC/local diagram from the "Mind the Gap" section, am I
> correct in thinking that the modified invariant that also covers times
> in a gap is:
>
>     dt ==
> datetime.fromtimestamp(dt.astimezone(utc).astimezone(dt.tzinfo).timestamp())
>
> That is, for local times that exist, the invariant "dt ==
> dt.astimezone(utc).astimezone(dt.tzinfo)" holds, but 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()".
>

That can't be right -- There is no way any fromtimestamp() call can return
a time in the gap. I think about the only useful invariant here is

  dt.timestamp() == dt.astimezone(utc).timestamp() == dt.astimezone(<any
other tz>).timestamp()


> Regards,
> Nick.
>
> P.S. Thanks to whoever drew the diagrams for the In the Fold/Mind the
> Gap sections - I found them incredibly helpful in understanding the
> change!
>

You're welcome. It was a collaboration by myself and Alexander. I drew the
first version by hand because I couldn't follow the math without a visual
aid. :-)

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20150922/e82d7a82/attachment.html>
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4