From f83e711ed7d38673b057b1c32a3bd72b2532e94a Mon Sep 17 00:00:00 2001 From: Michael Twomey Date: Thu, 17 Oct 2013 21:28:58 +0100 Subject: Z always specifies UTC now Thanks to vfaronov Fixes #5 --- README.rst | 1 + iso8601/iso8601.py | 2 +- iso8601/test_iso8601.py | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 6da8b2d..29889e5 100644 --- a/README.rst +++ b/README.rst @@ -74,6 +74,7 @@ Changes * Fix microsecond rounding issues (https://bitbucket.org/micktwomey/pyiso8601/issue/2/roundoff-issues-when-parsing-decimal) (thanks to nielsenb@jetfuse.net) * Fix pickling and deepcopy of returned datetime objects (https://bitbucket.org/micktwomey/pyiso8601/issue/3/dates-returned-by-parse_date-do-not) (thanks to fogathmann and john@openlearning.com) * Fix timezone offsets without a separator (https://bitbucket.org/micktwomey/pyiso8601/issue/4/support-offsets-without-a-separator) (thanks to joe.walton.gglcd) +* "Z" produces default timezone if one is specified (https://bitbucket.org/micktwomey/pyiso8601/issue/5/z-produces-default-timezone-if-one-is) (thanks to vfaronov). This one may cause problems if you've been relying on default_timezone to use that timezone instead of UTC. Strictly speaking that was wrong but this is potentially backwards incompatible. 0.1.4 ----- diff --git a/iso8601/iso8601.py b/iso8601/iso8601.py index 86c076b..2be28dc 100644 --- a/iso8601/iso8601.py +++ b/iso8601/iso8601.py @@ -134,7 +134,7 @@ def parse_timezone(matches, default_timezone=UTC): """ if matches["timezone"] == "Z": - return default_timezone + return UTC # This isn't strictly correct, but it's common to encounter dates without # timezones so I'll assume the default (which defaults to UTC). # Addresses issue 4. diff --git a/iso8601/test_iso8601.py b/iso8601/test_iso8601.py index 079663d..7a3c7a0 100644 --- a/iso8601/test_iso8601.py +++ b/iso8601/test_iso8601.py @@ -18,6 +18,14 @@ def test_parse_no_timezone_different_default(): assert d == datetime.datetime(2007, 1, 1, 8, 0, 0, 0, tz) assert d.tzinfo == tz +def test_parse_utc_different_default(): + """Z should mean 'UTC', not 'default'. + + """ + tz = iso8601.FixedOffset(2, 0, "test offset") + d = iso8601.parse_date("2007-01-01T08:00:00Z", default_timezone=tz) + assert d == datetime.datetime(2007, 1, 1, 8, 0, 0, 0, iso8601.UTC) + @pytest.mark.parametrize("invalid_date", [ ("2013-10-",), ("2013-",), -- cgit v1.2.1