Skip to content

Zero-pad ISO week years when formatting W tokens - #1371

Open
Alex0AI wants to merge 1 commit into
arrow-py:masterfrom
Alex0AI:fix/iso-week-year-padding
Open

Alex0AI wants to merge 1 commit into
arrow-py:masterfrom
Alex0AI:fix/iso-week-year-padding

Conversation

@Alex0AI

@Alex0AI Alex0AI commented Oct 9, 2026

Copy link
Copy Markdown

Summary

The documented ISO week-date token W emits a variable-width year for dates before year 1000. For example:

import arrow
arrow.get(1, 1, 1).format("W")  # currently "1-W01-1", expected "0001-W01-1"

Pad the ISO week year to four digits, keeping the existing ISO week/year calculation. Add seven regression cases through both DateTimeFormatter.format() and the public Arrow.format() API: one-, two-, three-, and four-digit years, the minimum and maximum datetime years, and a December date belonging to the following ISO year.

This addresses formatted output only; it does not change week-date parsing or overlap with #1338's week-53 validation.

Verification

  • Before the fix: 4 new regression cases failed, 3 passed.
  • Full test suite on Windows/Python 3.13: python -m pytest -q -o addopts='': 1908 passed, 1 skipped.
  • Black check and Flake8 passed for both modified Python files.
  • git diff --check passed.

AI assistance disclosure: OpenAI Codex investigated, implemented, tested, and drafted this description.

@codecov

codecov Bot commented Oct 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2224255) to head (299aa03).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #1371   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10        10           
  Lines         2315      2315           
  Branches       358       358           
=========================================
  Hits          2315      2315           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@Wkhanex Wkhanex left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The W formatter produces four-digit ISO week years for years 1, 9, 99 and 999 as well as ordinary modern dates. January and December rollover cases agree with datetime.isocalendar(), which is useful because the ISO week year can differ from the calendar year.

Checked 299aa03b480b with standalone Python 3.12.14 checks (28 passing assertions). I haven't run the full upstream suite.

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.

2 participants