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

Alexander Belopolsky alexander.belopolsky at gmail.com
Sun Sep 13 04:40:33 CEST 2015

On Sat, Sep 12, 2015 at 10:25 PM, Tim Peters <tim.peters at gmail.com> wrote:

> > I will try to create a  zoneinfo wrapping prototype as well, but I will
> > probably "cheat" and build it on top of pytz.
> It would be crazy not to ;-)  Note that Stuart got to punt on "the
> hard part":  .utcoffset(), since pytz only uses fixed-offset classes.
> For a prototype - and possibly forever after - I'd be inclined to
> create an exhaustive list of transition times in local time, parallel
> to the list of such times already there in UTC.

Yes.  The only complication is that you need four transition points instead
of two per year in a regular DST case: (1) start of gap; (2) end of gap;
(3) start of fold; and (4) end of fold.  Once you know where you are with
respect to those points, figuring out utcoffset(), dst() and tzname() for
either value of fold is trivial.

>   An index into either
> list then gives an index into the other, and into the list of
> information about the transition (total offset, is_dst, etc).


It's a shame though to work from a transitions in UTC list because most of
DST rules are expressed in local times and then laboriously converted into
UTC.  I think I should also implement the POSIX TZ spec tzinfo.  This is
where the advantage of the "as intended" approach will be obvious.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150912/f7b15506/attachment.html>

More information about the Python-list mailing list