Skip to content

Fix week formatting at the maximum supported year - #1403

Closed
KennyMcSimpson wants to merge 1 commit into
python-babel:masterfrom
KennyMcSimpson:fix/format-week-at-max-year
Closed

KennyMcSimpson wants to merge 1 commit into
python-babel:masterfrom
KennyMcSimpson:fix/format-week-at-max-year

Conversation

@KennyMcSimpson

Copy link
Copy Markdown

Formatting date.max or datetime.max with a week field raises ValueError: year 10000 is out of range for locales such as en_US, en_AU and aa_DJ. get_week_of_year() constructs the following January 1 only to obtain its weekday. Derive that weekday from the current December 31 instead, keeping the calculation inside Python's date range and preserving the existing locale week rules.

Add 24 regression/control cases for both public formatters at both supported date boundaries across all six CLDR week rules. Against unchanged production code, eight maximum-year cases fail and sixteen controls pass. With the fix, all 24 pass; an independent all-locale boundary audit also passes all 4,484 checks (previously 1,944 failures).

Validation: complete Python 3.13 suite (7,853 passed, nine skipped, two expected failures; 93% coverage), date tests and doctests on Python 3.10 (2,464 passed, two expected failures), full Ruff and whitespace checks. Tested on Windows with repository-pinned CLDR 48.2 data.

Prepared with OpenAI Codex assistance; no independent human review is claimed.

Derive the next January weekday from December 31 to avoid constructing an out-of-range date for valid date.max and datetime.max values. Cover all six CLDR week rules at both supported date boundaries.
@akx

akx commented Oct 26, 2026

Copy link
Copy Markdown
Member

Sorry, I don't think this is necessary. We can get back to this once formatting such datetimes are a pressing issue.

@akx akx closed this Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants