Skip to content

Preserve four-digit years when parsing day-of-year formats - #1041

Open
shguild wants to merge 3 commits into
python-pendulum:masterfrom
shguild:fix/ordinal-year-padding
Open

shguild wants to merge 3 commits into
python-pendulum:masterfrom
shguild:fix/ordinal-year-padding

Conversation

@shguild

@shguild shguild commented Oct 11, 2026

Copy link
Copy Markdown

from_format() cannot round-trip day-of-year formats for years before 1000. For example, pendulum.from_format("0001-031", "YYYY-DDDD") raises ParserError: Unable to parse string [1-031], although the original string is valid. The formatter converts the year to an integer and then reconstructs the ISO ordinal date without padding it back to four digits.

Keep the year zero-padded when constructing that intermediate date. Add coverage for DDD and DDDD, the minimum and maximum years, a leap day, the year 1000 boundary, time/offset preservation, and invalid dates. The new 16 cases produce 9 failures and 7 passes on the original code.

Validation on Windows / Python 3.12.14:

  • Pure Python full suite: 1884 passed, 5 skipped.
  • Current Python sources with the official 3.2.0 Rust extension: 1884 passed, 5 skipped. The Rust sources were not rebuilt locally.
  • mypy: success, 228 source files.
  • Ruff 0.14.11 lint and format checks pass for both changed Python files.
  • git diff --check passes.

Pull Request Check List

  • Added tests for changed code.
  • Updated the changelog for the bug fix.

Prepared with Codex (GPT-6) assistance.

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.

1 participant