]> granicus.if.org Git - python/commit
A new, and much hairier, implementation of astimezone(), building on
authorTim Peters <tim.peters@gmail.com>
Tue, 31 Dec 2002 17:36:56 +0000 (17:36 +0000)
committerTim Peters <tim.peters@gmail.com>
Tue, 31 Dec 2002 17:36:56 +0000 (17:36 +0000)
commit521fc15e626ed53ba90c966c4a2392ab487fd62e
tree586b22e2773638958fe158c29a04d41d1af179e1
parentba2f875d90c5b8650d6bde2a152be8f899e15469
A new, and much hairier, implementation of astimezone(), building on
an idea from Guido.  This restores that the datetime implementation
never passes a datetime d to a tzinfo method unless d.tzinfo is the
tzinfo instance whose method is being called.  That in turn allows
enormous simplifications in user-written tzinfo classes (see the Python
sandbox US.py and EU.py for fully fleshed-out examples).

d.astimezone(tz) also raises ValueError now if d lands in the one hour
of the year that can't be expressed in tz (this can happen iff tz models
both standard and daylight time).  That it used to return a nonsense
result always ate at me, and it turned out that it seemed impossible to
force a consistent nonsense result under the new implementation (which
doesn't know anything about how tzinfo classes implement their methods --
it can only infer properties indirectly).  Guido doesn't like this --
expect it to change.

New tests of conversion between adjacent DST-aware timezones don't pass
yet, and are commented out.

Running the datetime tests in a loop under a debug build leaks 9
references per test run, but I don't believe the datetime code is the
cause (it didn't leak the last time I changed the C code, and the leak
is the same if I disable all the tests that invoke the only function
that changed here).  I'll pursue that next.
Lib/test/test_datetime.py
Modules/datetimemodule.c