summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--iso8601/iso8601.py12
-rw-r--r--iso8601/test_iso8601.py11
2 files changed, 18 insertions, 5 deletions
diff --git a/iso8601/iso8601.py b/iso8601/iso8601.py
index 38266c3..c852062 100644
--- a/iso8601/iso8601.py
+++ b/iso8601/iso8601.py
@@ -34,7 +34,7 @@ class ParseError(Exception):
ZERO = timedelta(0)
class Utc(tzinfo):
"""UTC
-
+
"""
def utcoffset(self, dt):
return ZERO
@@ -48,7 +48,7 @@ UTC = Utc()
class FixedOffset(tzinfo):
"""Fixed offset in hours and minutes from UTC
-
+
"""
def __init__(self, offset_hours, offset_minutes, name):
self.__offset = timedelta(hours=offset_hours, minutes=offset_minutes)
@@ -62,13 +62,13 @@ class FixedOffset(tzinfo):
def dst(self, dt):
return ZERO
-
+
def __repr__(self):
return "<FixedOffset %r>" % self.__name
def parse_timezone(tzstring, default_timezone=UTC):
"""Parses ISO 8601 time zone specs into tzinfo offsets
-
+
"""
if tzstring == "Z":
return default_timezone
@@ -87,7 +87,7 @@ def parse_timezone(tzstring, default_timezone=UTC):
def parse_date(datestring, default_timezone=UTC):
"""Parses ISO 8601 dates into datetime objects
-
+
The timezone is parsed from the date string. However it is quite common to
have dates without a timezone (not strictly correct). In this case the
default timezone specified in default_timezone is used. This is UTC by
@@ -104,6 +104,8 @@ def parse_date(datestring, default_timezone=UTC):
groups["fraction"] = 0
else:
groups["fraction"] = int(float("0.%s" % groups["fraction"]) * 1e6)
+ if groups["second"] is None:
+ groups["second"] = 0
return datetime(int(groups["year"]), int(groups["month"]), int(groups["day"]),
int(groups["hour"]), int(groups["minute"]), int(groups["second"]),
int(groups["fraction"]), tz)
diff --git a/iso8601/test_iso8601.py b/iso8601/test_iso8601.py
index 44cdc77..caa6b4c 100644
--- a/iso8601/test_iso8601.py
+++ b/iso8601/test_iso8601.py
@@ -93,6 +93,17 @@ def test_parse_no_timezone():
assert d.microsecond == 0
assert d.tzinfo == iso8601.UTC
+def test_parse_no_seconds():
+ d = iso8601.parse_date("1997-07-16T19:20+01:00")
+ assert d.year == 1997
+ assert d.month == 7
+ assert d.day == 16
+ assert d.hour == 19
+ assert d.minute == 20
+ assert d.second == 0
+ assert d.microsecond == 0
+ assert d.tzinfo.tzname(None) == "+01:00"
+
def test_parse_no_timezone_different_default():
tz = iso8601.FixedOffset(2, 0, "test offset")
d = iso8601.parse_date("2007-01-01T08:00:00", default_timezone=tz)