Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rust/src/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand All @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions src/pendulum/parsing/iso8601.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/parsing/test_parse_iso8601.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down