Skip to content

Commit 9ba4aab

Browse files
committed
Fix non-padded month parsing for ISO-8601. Also added test.
1 parent ea1d8fb commit 9ba4aab

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

pendulum/parsing/iso8601.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
" (?P<classic>" # Classic date (YYYY-MM-DD) or ordinal (YYYY-DDD)
2323
" (?P<year>\d{4})" # Year
2424
" (?P<monthday>"
25-
" (?P<monthsep>-)?(?P<month>\d{2})" # Month (optional)
25+
" (?P<monthsep>-)?(?P<month>\d{1,2})" # Month (optional)
2626
" ((?P<daysep>-)?(?P<day>\d{1,2}))?" # Day (optional)
2727
" )?"
2828
" )"

tests/parsing/test_parse_iso8601.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ def test_parse_iso8601():
1616
assert date(2016, 10, 6) == parse_iso8601("2016-10-06")
1717
assert date(2016, 10, 6) == parse_iso8601("20161006")
1818

19+
# Month only, both padded and unpadded
20+
assert date(2016, 7, 1) == parse_iso8601("2016-7")
21+
assert date(2016, 7, 1) == parse_iso8601("2016-07")
22+
1923
# Time
2024
assert time(20, 16, 10, 0) == parse_iso8601("201610")
2125

0 commit comments

Comments
 (0)