Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion babel/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1652,7 +1652,7 @@ def format_year(self, char: str, num: int) -> str:
elif month == 12 and self.value.day > 25 and self.get_week_of_year() <= 2:
value += 1
year = self.format(value, num)
if num == 2:
if num == 2 and char != 'u': # "uu" is a minimum width, not a truncation
year = year[-2:]
return year

Expand Down
15 changes: 15 additions & 0 deletions tests/test_date_time_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ def test_quarter_format():
assert fmt['QQQQQ'] == '4'


def test_extended_year_is_not_truncated():
# UTS #35: "For 'u', all field lengths specify a minimum number of digits;
# there is no special interpretation for 'uu'."
fmt = DateTimeFormat(date(2006, 6, 8), locale='en_US')
assert fmt['yy'] == '06'
assert fmt['YY'] == '06'
assert fmt['u'] == '2006'
assert fmt['uu'] == '2006'
assert fmt['uuu'] == '2006'
fmt = DateTimeFormat(date(5, 6, 8), locale='en_US')
assert fmt['u'] == '5'
assert fmt['uu'] == '05'
assert fmt['uuuu'] == '0005'


def test_month_context():
d = date(2006, 2, 8)
assert DateTimeFormat(d, locale='mt_MT')['MMMMM'] == 'F' # narrow format
Expand Down