summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjulien <julien@danjou.info>2014-02-18 15:36:36 +0100
committerjulien <julien@danjou.info>2014-02-18 15:36:36 +0100
commit677df693ce687bbf3185bfd2fdfea715d9916967 (patch)
tree8317d578701c399aeb0f6338c74614d13104f8ef
parentc310ac5c62a10171d3502358368a91a52b014f38 (diff)
downloadpyiso8601-677df693ce687bbf3185bfd2fdfea715d9916967.tar.gz
Raise error when parsing year with wrong number for years
Closes #12
-rw-r--r--iso8601/iso8601.py36
-rw-r--r--iso8601/test_iso8601.py5
2 files changed, 23 insertions, 18 deletions
diff --git a/iso8601/iso8601.py b/iso8601/iso8601.py
index 35dc31f..4907fbd 100644
--- a/iso8601/iso8601.py
+++ b/iso8601/iso8601.py
@@ -35,24 +35,28 @@ ISO8601_REGEX = re.compile(
(-{0,1}(?P<month>[0-9]{1,2})){1}
(-{0,1}(?P<day>[0-9]{1,2})){1}
(
- (?P<separator>[ T])
- (?P<hour>[0-9]{2})
- (:{0,1}(?P<minute>[0-9]{2})){0,1}
(
- :{0,1}(?P<second>[0-9]{1,2})
- (\.(?P<second_fraction>[0-9]+)){0,1}
- ){0,1}
- (?P<timezone>
- Z
- |
+ (?P<separator>[ T])
+ (?P<hour>[0-9]{2})
+ (:{0,1}(?P<minute>[0-9]{2})){0,1}
(
- (?P<tz_sign>[-+])
- (?P<tz_hour>[0-9]{2})
- :{0,1}
- (?P<tz_minute>[0-9]{2}){0,1}
- )
- ){0,1}
- ){0,1}
+ :{0,1}(?P<second>[0-9]{1,2})
+ (\.(?P<second_fraction>[0-9]+)){0,1}
+ ){0,1}
+ (?P<timezone>
+ Z
+ |
+ (
+ (?P<tz_sign>[-+])
+ (?P<tz_hour>[0-9]{2})
+ :{0,1}
+ (?P<tz_minute>[0-9]{2}){0,1}
+ )
+ ){0,1}
+ )
+ |
+ $
+ )
""",
re.VERBOSE
)
diff --git a/iso8601/test_iso8601.py b/iso8601/test_iso8601.py
index aac68bb..ffff85d 100644
--- a/iso8601/test_iso8601.py
+++ b/iso8601/test_iso8601.py
@@ -27,15 +27,16 @@ def test_parse_utc_different_default():
assert d == datetime.datetime(2007, 1, 1, 8, 0, 0, 0, iso8601.UTC)
@pytest.mark.parametrize("invalid_date, error_string", [
- ("2013-10-", "day is out of range for month"),
+ ("2013-10-", "Unable to parse date string"),
("2013-", "Unable to parse date string"),
("", "Unable to parse date string"),
(None, "Expecting a string"),
("23", "Unable to parse date string"),
# ("131015T142533Z", "Unable to parse date string"), FIXME
# ("131015", "Unable to parse date string"), FIXME
- # ("2007-06-23X06:40:34.00Z", "Unable to parse date string"), # https://code.google.com/p/pyiso8601/issues/detail?id=14 FIXME
+ ("2007-06-23X06:40:34.00Z", "Unable to parse date string"), # https://code.google.com/p/pyiso8601/issues/detail?id=14
# ("2007-06-23 06:40:34.00Zrubbish", "Unable to parse date string"), # https://code.google.com/p/pyiso8601/issues/detail?id=14 FIXME
+ ("20114-01-03T01:45:49", "Unable to parse date string"),
])
def test_parse_invalid_date(invalid_date, error_string):
with pytest.raises(iso8601.ParseError) as exc: