Pewarta Proxy

📋 Server Request & Proxy Logs

Loading active proxy settings...
Developed by Khairul Adha (adhexa.id)
Mengambil log server...

⚙️ Pengaturan Proxy Target

Skip to content

Fix ISO 8601 week dates with years < 1000 - #1077

Open
rahul05ranjan wants to merge 1 commit into
python-pendulum:masterfrom
rahul05ranjan:fix-iso8601-week-date-year-padding
Open

rahul05ranjan wants to merge 1 commit into
python-pendulum:masterfrom
rahul05ranjan:fix-iso8601-week-date-year-padding

Conversation

@rahul05ranjan

Copy link
Copy Markdown

Fixes #1076.

Summary

pendulum.parse() rejected every ISO 8601 week date whose year is below 1000 — 0999-W34-6, 0416-W34-6, 0416W346, 0416-W34, 0004-W10-5 — with a generic ParserError, while datetime.fromisoformat accepts all of them and the same years parse fine in calendar form (0416-08-21). The boundary was exact: 1000-W34-6 worked, 0999-W34-6 did not.

Root cause

src/pendulum/parsing/iso8601.py, _get_iso_8601_week:

fmt = "%Y-%j"
string = f"{year}-{ordinal}"
dt = datetime.datetime.strptime(string, fmt)

The year is interpolated without zero-padding, so year 416 produces "416-240"; strptime's %Y matches exactly four digits, and the resulting ValueError is masked into the generic ParserError("Unable to parse string [...]") by _parse.

Fix

Pad the year to four digits: f"{year:04d}-{ordinal}".

Verification

  • 5 regression cases added to the parametrized week-date test in tests/parsing/test_parse_iso8601.py (0999-W34-6, 0416-W34-6, 0004-W10-5, 0416W346, 0416-W34).
  • Full tests/parsing suite: 88 passed (83 baseline + 5 new).
  • Week-53 validation still intact: 0999-W53-7 correctly raises (999 is not a long year).
  • tests/datetime/test_from_format.py failure set unchanged (the 49 pre-existing failures are the time-machine-gated travel tests, unavailable in this environment).
  • Python 3.13, Linux.

_get_iso_8601_week built the intermediate string as
f"{year}-{ordinal}" without zero-padding, but strptime's %Y matches
exactly four digits, so every week date in a year below 1000
(0999-W34-6, 0416W346, 0004-W10-5, ...) failed with a generic
ParserError while datetime.fromisoformat accepts them and the same
years parse fine in calendar form.

Pad the year to 4 digits.

Fixes python-pendulum#1076

Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parse() rejects ISO 8601 week dates with years < 1000 (strptime %Y needs zero-padding)

1 participant