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
3 changes: 2 additions & 1 deletion src/pendulum/parsing/iso8601.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,8 @@ def _get_iso_8601_week(
year += 1

fmt = "%Y-%j"
string = f"{year}-{ordinal}"
# %Y matches exactly four digits; years below 1000 must be zero-padded.
string = f"{year:04d}-{ordinal}"

dt = datetime.datetime.strptime(string, fmt)

Expand Down
7 changes: 7 additions & 0 deletions tests/parsing/test_parse_iso8601.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
("2008-W39-6", date(2008, 9, 27)),
("2009-W53-7", date(2010, 1, 3)),
("2009-W01-1", date(2008, 12, 29)),
# Week dates with years below 1000 (%Y needs four digits)
("1000-W34-6", date(1000, 8, 23)),
("0999-W34-6", date(999, 8, 24)),
("0416-W34-6", date(416, 8, 27)),
("0416W346", date(416, 8, 27)),
("0416-W34", date(416, 8, 22)),
("0004-W10-5", date(4, 3, 5)),
# Time
("12:34", time(12, 34, 0)),
("12:34:56", time(12, 34, 56)),
Expand Down