babel icon indicating copy to clipboard operation
babel copied to clipboard

Handling of day period format "b" seems incorrect

Open dairiki opened this issue 2 years ago • 2 comments

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:

  • "6:00 am", "12:00 noon", "6:00 pm", "12:00 midnight" seems more usable than "6:00 morning", "6:00 evening".
  • There is the "B" format field if one wants "in the evening".

dairiki avatar Aug 16 '23 18:08 dairiki

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

caitlinlilley avatar Oct 03 '23 00:10 caitlinlilley

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

  • https://github.com/unicode-org/cldr/blob/release-42/common/supplemental/dayPeriods.xml#L18
  • https://github.com/unicode-org/cldr/blob/release-42/common/main/en.xml#L2350
>>> 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'

jun66j5 avatar Oct 03 '23 02:10 jun66j5