Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dairiki opened this issue Aug 16, 2023 · 2 comments
Open

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

dairiki opened this issue Aug 16, 2023 · 2 comments

Comments

@dairiki
Copy link

dairiki commented Aug 16, 2023

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".
@caitlinlilley
Copy link

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

@jun66j5
Copy link
Contributor

jun66j5 commented Oct 3, 2023

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants