diff --git a/pendulum/parsing/__init__.py b/pendulum/parsing/__init__.py index 58f60a99..44455cb5 100644 --- a/pendulum/parsing/__init__.py +++ b/pendulum/parsing/__init__.py @@ -16,11 +16,11 @@ # Date (optional) "^" "(?P" - " (?P" # Classic date (YYYY-MM-DD) + " (?P" # Classic date (YYYY:MM:DD) or (YYYY-MM-DD) or (YYYY/MM/DD) " (?P\d{4})" # Year " (?P" - " (?P[/:])?(?P\d{2})" # Month (optional) - " ((?P[/:])?(?P\d{2}))" # Day (optional) + " (?P[/:-])?(?P\d{1,2})" # Month (optional) + " ((?P[/:-])?(?P\d{1,2}))?" # Day (optional) " )?" " )" ")?" @@ -160,7 +160,7 @@ def _parse_common(text, **options): day = int(m.group("month")) else: month = int(m.group("month")) - day = int(m.group("day")) + day = int(m.group("day") or 1) if not m.group("time"): return date(year, month, day) diff --git a/tests/parsing/test_parsing.py b/tests/parsing/test_parsing.py index 19f532d4..83f04fc8 100644 --- a/tests/parsing/test_parsing.py +++ b/tests/parsing/test_parsing.py @@ -680,3 +680,7 @@ def test_exif_edge_case(): assert 15 == parsed.hour assert 45 == parsed.minute assert 28 == parsed.second + +def test_month_padding(): + # This shouldn't raise an exceptionf + pendulum.parse('2016-7')