Issue #11 new

Allow pytz.timezone arguments for default_timezone (patch)

Michael Twomey
repo owner created an issue

Original: https://code.google.com/p/pyiso8601/issues/detail?id=13

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.

 Deleted: iso8601_pytz_patch.diff

645 bytes

Nov 18, 2009 Delete comment #1 d.j.batley oops -- that patch obviously gives the wrong answer (gives date as utc in local timezone). Sorry!

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.

Comments (1)

  1. Log in to comment