diff --git a/rust/src/parsing.rs b/rust/src/parsing.rs index 374fe3cfb..e3a860986 100644 --- a/rust/src/parsing.rs +++ b/rust/src/parsing.rs @@ -347,6 +347,8 @@ impl<'a> Parser<'a> { } Err(error) => return Err(error), } + } else if self.end() { + // Year only (YYYY): month and day keep their default of 1 } else { /* Month and day in compact format (MMDD) or ordinal date (DDD) diff --git a/tests/parsing/test_parse_iso8601.py b/tests/parsing/test_parse_iso8601.py index ed2d39887..b1ee2da24 100644 --- a/tests/parsing/test_parse_iso8601.py +++ b/tests/parsing/test_parse_iso8601.py @@ -18,6 +18,7 @@ @pytest.mark.parametrize( ["text", "expected"], [ + ("2016", date(2016, 1, 1)), ("2016-10", date(2016, 10, 1)), ("2016-10-06", date(2016, 10, 6)), # Ordinal date diff --git a/tests/test_parsing.py b/tests/test_parsing.py index 34673c40a..52153a9fb 100644 --- a/tests/test_parsing.py +++ b/tests/test_parsing.py @@ -127,6 +127,14 @@ def test_parse_interval() -> None: assert interval.end.offset == 0 +def test_parse_interval_of_years() -> None: + interval = pendulum.parse("2016/2017") + + assert isinstance(interval, pendulum.Interval) + assert interval.start == pendulum.date(2016, 1, 1) + assert interval.end == pendulum.date(2017, 1, 1) + + def test_parse_now() -> None: assert pendulum.parse("now").timezone_name == "UTC" assert (