diff --git a/rust/src/parsing.rs b/rust/src/parsing.rs index 374fe3cfb..4c3d967b6 100644 --- a/rust/src/parsing.rs +++ b/rust/src/parsing.rs @@ -833,7 +833,7 @@ impl<'a> Parser<'a> { iso_week: u32, iso_day: u32, ) -> Result<(u32, u32, u32), ParseError> { - if iso_week > 53 || iso_week > 52 && !is_long_year(iso_year as i32) { + if iso_week < 1 || iso_week > 53 || iso_week > 52 && !is_long_year(iso_year as i32) { return Err(ParseError { index: self.idx, message: format!( @@ -842,7 +842,7 @@ impl<'a> Parser<'a> { }); } - if iso_day > 7 { + if iso_day < 1 || iso_day > 7 { return Err(ParseError { index: self.idx, message: "Invalid ISO date: week day is invalid".to_string(), diff --git a/src/pendulum/parsing/iso8601.py b/src/pendulum/parsing/iso8601.py index c65d249e5..8684c4f22 100644 --- a/src/pendulum/parsing/iso8601.py +++ b/src/pendulum/parsing/iso8601.py @@ -426,10 +426,10 @@ def _get_iso_8601_week( year = int(year) week = int(week) - if week > 53 or (week > 52 and not is_long_year(year)): + if week < 1 or week > 53 or (week > 52 and not is_long_year(year)): raise ParserError("Invalid week for week date") - if weekday > 7: + if weekday < 1 or weekday > 7: raise ParserError("Invalid weekday for week date") # We can't rely on strptime directly here since diff --git a/tests/parsing/test_parse_iso8601.py b/tests/parsing/test_parse_iso8601.py index ed2d39887..5a82256c8 100644 --- a/tests/parsing/test_parse_iso8601.py +++ b/tests/parsing/test_parse_iso8601.py @@ -160,6 +160,10 @@ def test_parse_iso8601_invalid(): # Invalid week date with pytest.raises(ValueError): parse_iso8601("2012-W63") + with pytest.raises(ValueError): + parse_iso8601("2015-W00") + with pytest.raises(ValueError): + parse_iso8601("2015-W01-0") with pytest.raises(ValueError): parse_iso8601("2012-W12-9") with pytest.raises(ValueError):