Reported by d.j.batley, Nov 18, 2009 pytz breaks if you pass the "tzinfo" argument when creating a datetime object (it's a problem for it to work out daylight saving time or not, so it gives an "obviously wrong" answer).
If we provide a default_timezone which is a pytz, the output is nonsense:
china_timezone = pytz.timezone("PRC") utc_timezone = pytz.timezone("UTC") d = iso8601.parse_date("2009-11-18 21:00:00", default_timezone=china_timezone) print d.astimezone(utc_timezone).isoformat() 2009-11-18T12:54:00+00:00
(the correct answer is "2009-11-18T21:00:00+00:00")
The way to solve it is to pass tzinfo=UTC when making the datetime, and then convert to whatever timezone. A patch to do this is attached.
Nov 18, 2009 Delete comment
oops -- that patch obviously gives the wrong answer (gives date as utc in local
datetime(...).replace(tzinfo=tz) does the same as passing tzinfo when creating the object.
I'm not entirely sure there is an answer to this one, although this works:
china_timezone.localize(iso8601.parse_date("2009-11-18 21:00:00", default_timezone=None)) But localize is only implemented in pytz, so it's not a generalized solution.