python-babel / babel

The official repository for Babel, the Python Internationalization Library
http://babel.pocoo.org/
BSD 3-Clause "New" or "Revised" License
1.29k stars 433 forks source link

Handling of day period format "b" seems incorrect #1023

Open dairiki opened 10 months ago

dairiki commented 10 months ago

Overview Description

The "b" format symbol to format_time and format_datetime (with locale="en") currently produces one of morning, noon, evening, or midnight.

The CLDR docs say the result should be one of am, noon, pm, or midnight.

(The latter behavior seems more useful.)

Steps to Reproduce

import datetime
from babel.dates import format_time

print(format_time(datetime.time(6), "h:mm b", locale="en"))

Actual Results

6:00 morning

Expected Results

6:00 am

Reproducibility

Babel versions 2.10.2 through 2.12.1 all behave consistently. Versions prior to 2.10.2 do not support the "b" field at all (#869).

Additional Information

Comments:

caitlinlilley commented 9 months ago

Hi, if this issue is still available I would like to be assigned to it.

jun66j5 commented 9 months ago

That is not a defect. In CLDR 42, morning is declared for period 6:00 <= time < 12:00 of "en" locale.

>>> import babel
>>> babel.__version__
'2.12.1'
>>> import datetime
>>> from babel import dates
>>> dates.format_time(datetime.time(5, 59, 59), 'h:mm b', locale='en')
'5:59 night'
>>> dates.format_time(datetime.time(6, 0, 0), 'h:mm b', locale='en')
'6:00 morning'
>>> dates.format_time(datetime.time(11, 59, 59), 'h:mm b', locale='en')
'11:59 morning'
>>> dates.format_time(datetime.time(12, 0, 0), 'h:mm b', locale='en')
'12:00 noon'
>>> dates.format_time(datetime.time(12, 0, 1), 'h:mm b', locale='en')
'12:00 afternoon'
>>> dates.format_time(datetime.time(17, 59, 59), 'h:mm b', locale='en')
'5:59 afternoon'
>>> dates.format_time(datetime.time(18, 0, 0), 'h:mm b', locale='en')
'6:00 evening'
>>> dates.format_time(datetime.time(20, 59, 59), 'h:mm b', locale='en')
'8:59 evening'
>>> dates.format_time(datetime.time(21, 0, 0), 'h:mm b', locale='en')
'9:00 night'