Skip to content

Support CLDR 48 relative date formats - #1306

Open
akx wants to merge 2 commits into
masterfrom
cldr-48-relative
Open

Support CLDR 48 relative date formats#1306
akx wants to merge 2 commits into
masterfrom
cldr-48-relative

Conversation

@akx

@akx akx commented Jul 30, 2026

Copy link
Copy Markdown
Member

New data in CLDR 48, let's make use of it!

@akx akx added this to the Babel 2.19 milestone Jul 30, 2026
@codspeed-hq

codspeed-hq Bot commented Jul 30, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 88 untouched benchmarks


Comparing cldr-48-relative (4734073) with master (95d2f60)

Open in CodSpeed

@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.21%. Comparing base (95d2f60) to head (4734073).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1306      +/-   ##
==========================================
+ Coverage   92.19%   92.21%   +0.02%     
==========================================
  Files          27       27              
  Lines        4764     4779      +15     
==========================================
+ Hits         4392     4407      +15     
  Misses        372      372              
Flag Coverage Δ
macos-14-3.10 91.27% <100.00%> (+0.02%) ⬆️
macos-14-3.11 91.21% <100.00%> (+0.02%) ⬆️
macos-14-3.12 91.42% <100.00%> (+0.02%) ⬆️
macos-14-3.13 91.42% <100.00%> (+0.02%) ⬆️
macos-14-3.14 91.39% <100.00%> (+0.02%) ⬆️
macos-14-3.15 91.39% <100.00%> (+0.02%) ⬆️
macos-14-3.8 91.14% <100.00%> (+0.02%) ⬆️
macos-14-3.9 91.20% <100.00%> (+0.02%) ⬆️
macos-14-pypy3.10 91.27% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.10 91.29% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.11 91.23% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.12 91.44% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.13 91.44% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.14 91.42% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.15 91.42% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.8 91.16% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.9 91.22% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-pypy3.10 91.29% <100.00%> (+0.02%) ⬆️
windows-2022-3.10 91.28% <100.00%> (+0.02%) ⬆️
windows-2022-3.11 91.22% <100.00%> (+0.02%) ⬆️
windows-2022-3.12 91.43% <100.00%> (+0.02%) ⬆️
windows-2022-3.13 91.43% <100.00%> (+0.02%) ⬆️
windows-2022-3.14 91.41% <100.00%> (+0.02%) ⬆️
windows-2022-3.15 91.41% <100.00%> (+0.02%) ⬆️
windows-2022-3.8 91.25% <100.00%> (+0.02%) ⬆️
windows-2022-3.9 91.21% <100.00%> (+0.02%) ⬆️
windows-2022-pypy3.10 91.28% <100.00%> (+0.02%) ⬆️

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.

@akx
akx requested review from Copilot and tomasr8 July 30, 2026 15:51
@akx
akx marked this pull request as ready for review July 30, 2026 15:52
@akx
akx force-pushed the cldr-48-relative branch from 726c4dd to 4734073 Compare July 30, 2026 15:54

Copilot AI 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.

Pull request overview

This PR updates Babel to take advantage of new CLDR 48 data for relative date wording and locale-specific patterns for combining relative dates with times (e.g., “tomorrow at 3:30 PM”).

Changes:

  • Add dates.get_relative_name() to retrieve CLDR literal relative names for specific offsets (e.g., yesterday/today/tomorrow; weekday-relative).
  • Add dates.format_relative_datetime() and import CLDR 48 relative datetime combination patterns.
  • Expand documentation and add comprehensive tests across multiple locales and widths.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/test_dates.py Adds coverage for relative-name retrieval and relative date+time formatting behavior across locales/lengths.
scripts/import_cldr.py Extends CLDR import to ingest literal relative names and relative datetime combination patterns.
docs/api/dates.rst Exposes new APIs in the generated documentation.
babel/dates.py Implements get_relative_name() and format_relative_datetime().
babel/core.py Adds Locale.datetime_formats_relative accessor for CLDR 48 relative datetime patterns.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread babel/core.py

.. versionadded:: 2.19
"""
return self._data['datetime_formats_relative']
Comment thread babel/dates.py
Comment on lines +859 to +863
locale = Locale.parse(locale or LC_TIME)
pattern = (
locale.datetime_formats_relative.get(format)
or locale.datetime_formats[format]
)
Comment thread tests/test_dates.py
assert dates.format_relative_datetime(
'demain', time(15, 30), format='full', locale='fr',
) == 'demain à 15:30:00 temps universel coordonné'
# Czech has no relative pattern, so falls back to datetime_formats

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.

Surprised there are no relative patterns since they should work fine here, but I guess they'll add them eventually..

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Mmmm, I think this is related to #1076...

Comment thread babel/dates.py
locale = Locale.parse(locale or LC_TIME)
date_fields = locale._data['date_fields']
key = field if length == 'long' else f'{field}-{length}'
data = date_fields.get(key) or date_fields.get(field)

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.

So if the specified length does not exist, you get the long version by default?

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.

3 participants