diff --git a/src/pendulum/parsing/iso8601.py b/src/pendulum/parsing/iso8601.py index c65d249e5..b57bc63a8 100644 --- a/src/pendulum/parsing/iso8601.py +++ b/src/pendulum/parsing/iso8601.py @@ -447,7 +447,9 @@ def _get_iso_8601_week( year += 1 fmt = "%Y-%j" - string = f"{year}-{ordinal}" + # %Y requires a zero-padded 4-digit year in strptime, so years < 1000 + # must be padded or the lookup fails. + string = f"{year:04d}-{ordinal}" dt = datetime.datetime.strptime(string, fmt) diff --git a/tests/parsing/test_parse_iso8601.py b/tests/parsing/test_parse_iso8601.py index ed2d39887..636fc875b 100644 --- a/tests/parsing/test_parse_iso8601.py +++ b/tests/parsing/test_parse_iso8601.py @@ -29,6 +29,12 @@ ("2008-W39-6", date(2008, 9, 27)), ("2009-W53-7", date(2010, 1, 3)), ("2009-W01-1", date(2008, 12, 29)), + # Week date with a year < 1000 (%Y in strptime needs the padding) + ("0999-W34-6", date(999, 8, 24)), + ("0416-W34-6", date(416, 8, 27)), + ("0004-W10-5", date(4, 3, 5)), + ("0416W346", date(416, 8, 27)), + ("0416-W34", date(416, 8, 22)), # Time ("12:34", time(12, 34, 0)), ("12:34:56", time(12, 34, 56)),