Allow pytz.timezone arguments for default_timezone (patch)

Michael Twomey avatarMichael Twomey 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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.