-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
locale.nl_langinfo(locale.ERA) does not work for past eras #126727
Comments
It now returns multiple era description segments separated by semicolons. Previously it only returned the first segment on platforms with Glibc.
On my computer (Linux) the following script import locale, subprocess
alllocales = subprocess.check_output(['locale', '-a']).decode().split()
for loc in alllocales:
if '.' in loc or '@' in loc:
continue
try:
_ = locale.setlocale(locale.LC_ALL, loc)
except locale.Error:
continue
era = locale.nl_langinfo(locale.ERA)
if era:
print(loc, era.count(';'), era) now produces the following output:
The ERA values are not set on FreeBSD and Illumos, and I suppose on macOS and Solaris too. It seems that currently they are only set on Linux. |
It now returns multiple era description segments separated by semicolons. Previously it only returned the first segment on platforms with Glibc.
Hi @serhiy-storchaka, I am sorry I couldn't test this earlier. While they are indeed not set on Illumos, we have them on Oracle Solaris for some locales:
Unfortunately, we have fewer Japanese ERAs than Linux (which causes the newly added test to fail), but I created #127327 to handle this. |
Bug report
According to the Posix specification (https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap07.html#tag_07_03_05_02),
nl_langinfo(ERA)
should return a string containing semicolon separated era description segments. But in Glibc it uses NUL instead of a semicolon as a separator. As result,locale.nl_langinfo(locale.ERA)
in Python only returns the first segment, corresponding to the last (current) era. For example, in Japanese locale the result cannot be used for data before year 2020:This issue is similar to #124969, but at least the result can be used for the current date.
cc @methane, @kulikjak.
Linked PRs
The text was updated successfully, but these errors were encountered: