Skip to content

Parse two-digit years relative to today in parse_date - #1449

Merged
akx merged 3 commits into
python-babel:masterfrom
jayhemnani9910:fix/parse-date-two-digit-year
Nov 9, 2026
Merged

akx merged 3 commits into
python-babel:masterfrom
jayhemnani9910:fix/parse-date-two-digit-year

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

parse_date('3/9/99', locale='en_US') returns 2099-03-09. A date from format_date(date(1999, 3, 9), 'short', locale='en_US') doesn't parse back to itself, and old dates such as birth dates land a century in the future.

Two-digit years now fall within 80 years before and 20 years after today, the window ICU and Java use. 4/1/04 is still 2004.

Added a test, it fails without the change. The test suite passes.

parse_date('3/9/99', locale='en_US') gave 2099-03-09, so a date formatted in
a short pattern did not parse back. Use the same window as ICU: 80 years
before and 20 years after today.

@akx akx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you augment the comment/docstring with a reference to the relevant ICU implementation source code, or better yet, a spec document?

@jayhemnani9910

Copy link
Copy Markdown
Contributor Author

Added to the docstring, with a link to ICU's SimpleDateFormat documentation, which states the 80 years before and 20 years after rule.

@akx akx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Augmented the tests a bit, etc. Thanks.

@akx
akx enabled auto-merge (squash) November 9, 2026 13:21
@akx akx added the area/dates label Nov 9, 2026
@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.64%. Comparing base (a18709c) to head (6852e5d).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1449      +/-   ##
==========================================
+ Coverage   93.62%   93.64%   +0.01%     
==========================================
  Files          27       27              
  Lines        4973     4986      +13     
==========================================
+ Hits         4656     4669      +13     
  Misses        317      317              
Flag Coverage Δ
macos-15-3.10 92.71% <100.00%> (?)
macos-15-3.11 92.65% <100.00%> (?)
macos-15-3.12 92.92% <100.00%> (?)
macos-15-3.13 ?
macos-15-3.14 92.90% <100.00%> (?)
macos-15-3.15 92.90% <100.00%> (+0.01%) ⬆️
macos-15-3.9 92.65% <100.00%> (?)
macos-15-pypy3.10 92.71% <100.00%> (?)
ubuntu-24.04-3.10 92.73% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.11 92.67% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.12 92.94% <100.00%> (?)
ubuntu-24.04-3.13 92.94% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.14 92.92% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.15 92.92% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.9 92.67% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-pypy3.10 92.73% <100.00%> (+0.01%) ⬆️
windows-2022-3.10 92.73% <100.00%> (+0.01%) ⬆️
windows-2022-3.11 92.67% <100.00%> (?)
windows-2022-3.12 92.93% <100.00%> (?)
windows-2022-3.13 92.93% <100.00%> (?)
windows-2022-3.14 92.91% <100.00%> (?)
windows-2022-3.15 92.91% <100.00%> (+0.01%) ⬆️
windows-2022-3.9 92.66% <100.00%> (+0.01%) ⬆️
windows-2022-pypy3.10 92.73% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed

codspeed Bot commented Nov 9, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 88 untouched benchmarks


Comparing jayhemnani9910:fix/parse-date-two-digit-year (6852e5d) with master (93846a2)

Open in CodSpeed

@akx
akx merged commit dc80d4c into python-babel:master Nov 9, 2026
32 of 33 checks passed
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