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

"B" symbol in pattern of dayperiod is not supported #866

Closed
jun66j5 opened this issue Apr 27, 2022 · 6 comments
Closed

"B" symbol in pattern of dayperiod is not supported #866

jun66j5 opened this issue Apr 27, 2022 · 6 comments

Comments

@jun66j5
Copy link
Contributor

jun66j5 commented Apr 27, 2022

Overview Description

(Originally reported in https://trac.edgewall.org/ticket/13482, running unit tests in Trac with Babel 2.10.1)

Since Babel 2.10.0 (CLDR 41), B symbol is used in datetime pattern for zh_Hant locale, however Babel doesn't support the B symbol.

Steps to Reproduce

>>> from datetime import datetime
>>> import pytz
>>> import babel
>>> from babel import dates
>>> babel.__version__
'2.10.1'
>>> dates.get_time_format('medium', 'zh_Hant')
<DateTimePattern 'Bh:mm:ss'>
>>> t1 = datetime(2010, 8, 28, 1, 45, 56, 0, pytz.UTC)
>>> t2 = datetime(2010, 8, 28, 13, 45, 56, 0, pytz.UTC)
>>> s1 = dates.format_datetime(t1, 'medium', t1.tzinfo, 'zh_Hant')
>>> s1
'2010年8月28日 B1:45:56'
>>> s2 = dates.format_datetime(t2, 'medium', t1.tzinfo, 'zh_Hant')
>>> s2
'2010年8月28日 B1:45:56'
>>> t1 == t2
False
>>> s1 == s2
True

Actual Results

The B symbol is not formatted.

Expected Results

The B symbol should be formatted to 上午 (am) or 下午 (pm).

Reproducibility

100%

Additional Information

n/a

@jun66j5
Copy link
Contributor Author

jun66j5 commented Apr 28, 2022

Only zh_Hant and zh_Hant_TW use B symbol for time format in Babel 2.10.1 (CLDR 41).

>>> import babel
>>> babel.__version__
'2.10.1'
>>> from babel.localedata import locale_identifiers
>>> from babel import dates
>>> for locale in locale_identifiers():
...   for format_ in formats:
...     pattern = dates.get_time_format(format=format_, locale=locale)
...     if 'b' in pattern.pattern or 'B' in pattern.pattern:
...       print(locale, width, pattern)
...
zh_Hant_TW full Bh:mm:ss [zzzz]
zh_Hant_TW full Bh:mm:ss [z]
zh_Hant_TW full Bh:mm:ss
zh_Hant_TW full Bh:mm
zh_Hant full Bh:mm:ss [zzzz]
zh_Hant full Bh:mm:ss [z]
zh_Hant full Bh:mm:ss
zh_Hant full Bh:mm

I noticed TODO comments for the b* and B* symbols in DateTimeFormat.__getitem__(). I'll try to fix if anyone has no interests about fix for the issue.

https://github.com/python-babel/babel/blob/v2.10.1/babel/dates.py#L1316-L1318

@akx
Copy link
Member

akx commented Apr 28, 2022

Thanks for the bug report and analysis.

A PR would be appreciated!

@jun66j5
Copy link
Contributor Author

jun66j5 commented Apr 28, 2022

Okay. I'm trying to fix it.... Hmm, I found the following change has been applied to test_zh_TW_format() while merging PR #826.

-    assert dates.format_time(datetime(2016, 4, 8, 12, 34, 56), locale='zh_TW') == u'\u4e0b\u534812:34:56'
+    assert dates.format_time(datetime(2016, 4, 8, 12, 34, 56), locale='zh_TW') == u'B12:34:56'

@akx
Copy link
Member

akx commented Apr 28, 2022

Okay. I'm trying to fix it.... Hmm, I found the following change has been applied to test_zh_TW_format() while merging PR #826.

That's an oversight on my part, sorry. I should have realized the B is wrong there. That test change should of course be reverted once the B character is supported.

@jun66j5
Copy link
Contributor Author

jun66j5 commented May 7, 2022

I've posted pull request #869 for this issue.

@akx
Copy link
Member

akx commented May 10, 2022

Closed via #869. Thank you!

@akx akx closed this as completed May 10, 2022
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

2 participants