Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #96559

Re: [Datetime-SIG] Are there any "correct" implementations of tzinfo?

From Laura Creighton <lac@openend.se>
Subject Re: [Datetime-SIG] Are there any "correct" implementations of tzinfo?
References (12 earlier) <CAExdVNkN465=bWeY61PFAxpiUQ-u0p2zaqtwH8PQWyQO4Jw9Mg@mail.gmail.com> <201509131600.t8DG07e0025688@fido.openend.se> <CAExdVNm3e43mJ3tqcUc9175WssV4zeuO024svJbMTjrTab=Qew@mail.gmail.com> <201509132031.t8DKVTwJ028027@fido.openend.se> <CAExdVNkeRVgV8CXLugMgqhUSuXU=qHYSFUo24Xw83X=8tVBjCg@mail.gmail.com>
Date 2015-09-14 10:27 +0200
Newsgroups comp.lang.python
Message-ID <mailman.523.1442219257.8327.python-list@python.org> (permalink)

Show all headers | View raw


In a message of Sun, 13 Sep 2015 16:58:09 -0500, Tim Peters writes:
>[Tim]
>>> Whatever time zone the traveler's railroad schedule uses, so long as
>>> it sticks to just one
>
>[Laura]
>> This is what does not happen.  Which is why I have written a python
>> app to perform conversions for my parents, in the past.
>
>So how did they get the right time zone rules for Creighton?

I was fortunate enough that they were never going there.  But in
investigating the problem I had it filed away under 'really ugly hacks
I might have to write in the future'.  Pre-parsing the file with
special mappings for special lookups seemed the only way to fix this,
at the time, but we have newer databases now than I had then ...
some of which might already know about Creighton.

>pytz solves it by _never_ creating a hybrid tzinfo.  It only uses
>eternally-fixed-offset tzinfos.  For example, for a conceptual zone
>with two possible total UTC offsets (one for "daylight", one for
>"standard"), there two distinct eternally-fixed-offset tzinfo objects
>in pytz.  Then an ambiguous time is resolved by _which_ specific
>tzinfo object is attached.  Typically the "daylight" tzinfo for the
>first time a repeated local time appears, and the "standard" tzinfo
>for its second appearance.

Yes.  I think this is a really great idea.  I have no idea why other
people disagree.

>In return, you have to use .localize() and .normalize() at various
>times, because pytz's tzinfo objects themselves are completely blind
>to the possibility of the total UTC offset changing. .localize() and
>.normalize() are needed to possibly _replace_ the tzinfo object in
>use, depending on the then-current date and time.

Yes.  

>OTOH, `dateutil` does create hybrid tzinfo objects.  No dances are
>ever needed to possibly replace them.  But it's impossible for
>dateutil's tzinfos to disambiguate times in a fold.  Incidentally,
>dateutil also makes no attempt to account for transitions other than
>DST (e.g., sometimes a zone may change its _base_ ("standard") offset
>from UTC).

I find this totally unacceptable.  My conclusion was that hybrid tzinfo
objects were a _really stupid idea_ proposed by somebody who misunderstood
the problem, or rather only understood the most common case.  Smack them
with a dead fish,  https://www.youtube.com/watch?v=i9SSOWORzw4
and get back to work.

>So, yup, if you're thoroughly indoctrinated in pytz behavior, you will
>be accurate but appear insane to Guido ;-)  At a semantic level, a
>pytz tzinfo doesn't capture the notion of a zone with offset changes -
>it doesn't even try to.  All knowledge about offset changes is inside
>the .localize() and .normalize() dances.

I can see why people would like to modify it to spit out this information
when asked.  I don't understand why they would like to have a hybrid
tzinfo.  The notion of replacing tzinfos when they become inappropriate
fills their souls with revulsion, or something?

But, as I said, once you know the pytz way you may be ruined for
appreciating other solutions.


Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: [Datetime-SIG] Are there any "correct" implementations of tzinfo? Laura Creighton <lac@openend.se> - 2015-09-14 10:27 +0200

csiph-web