Skip to content

Don't truncate "uu" extended years to two digits - #1539

Open
YouKnowChatta wants to merge 1 commit into
python-babel:masterfrom
YouKnowChatta:fix/extended-year-uu
Open

YouKnowChatta wants to merge 1 commit into
python-babel:masterfrom
YouKnowChatta:fix/extended-year-uu

Conversation

@YouKnowChatta

Copy link
Copy Markdown

DateTimeFormat.format_year() keeps only the last two digits of any two-letter year field. UTS #35 asks for that with yy and YY, but not with u. The Date Field Symbol Table says: "For 'u', all field lengths specify a minimum number of digits; there is no special interpretation for "uu"."

>>> from datetime import date
>>> from babel.dates import format_date
>>> format_date(date(2024, 3, 5), 'uu-MM-dd', locale='en')
'24-03-05'

ICU 78.3's SimpleDateFormat, called through PyICU, formats uu as 2024 for that date and as 05 for year 5. This change skips the truncation for u, so uu is a two-digit minimum width, and yy and YY still truncate. No date, time, datetime, skeleton, or interval pattern in the CLDR 49 data uses u, so the locales' own formats don't change.

The new test in tests/test_date_time_format.py fails before the change and passes after it. With CLDR 49 data on Python 3.15, python -X utf8 -m pytest reports 8294 passed, 3 skipped, and 2 xfailed, and the pre-commit hooks pass on both changed files.

UTS python-babel#35 gives two-letter truncation to "yy" and "YY" only. For "u" every field length is a minimum number of digits, so "uu" formats 2024 as 2024 and year 5 as 05.

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