summaryrefslogtreecommitdiff
path: root/iso8601/iso8601.py
diff options
context:
space:
mode:
Diffstat (limited to 'iso8601/iso8601.py')
-rw-r--r--iso8601/iso8601.py12
1 files changed, 7 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)