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

locale.nl_langinfo(locale.ERA) is broken #125411

Open
serhiy-storchaka opened this issue Oct 13, 2024 · 2 comments
Open

locale.nl_langinfo(locale.ERA) is broken #125411

serhiy-storchaka opened this issue Oct 13, 2024 · 2 comments
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Oct 13, 2024

Bug report

It is broken in the same way as locale.nl_langinfo(locale.ALT_DIGITS) was broken (see #124969), although not to the same degree. It returns the last (current) era.

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)

Output:

cmn_TW +:2:1913/01/01:+*:民國:%EC%Ey年
hak_TW +:2:1913/01/01:+*:民國:%EC%Ey年
ja_JP +:2:2020/01/01:+*:令和:%EC%Ey年
japanese +:2:2020/01/01:+*:令和:%EC%Ey年
lo_LA +:1:-543/01/01:+*:ພ.ສ.:%EC %Ey
lzh_TW +:2:1913/01/01:+*:民國:%EC%Ey年
nan_TW +:2:1913/01/01:+*:民國:%EC%Ey年
thai +:1:-543/01/01:+*:พ.ศ.:%EC %Ey
th_TH +:1:-543/01/01:+*:พ.ศ.:%EC %Ey
zh_TW +:2:1913/01/01:+*:民國:%EC%Ey年

The result is not completely useless, as it can be used to format and parse the current dates. But dates before the start of the current era (it is 2020 in Japan) cannot be proceeded.

The result should be a tuple, containing information for all eras, but this is a breaking change. So, perhaps such change cannot be backported.

cc @methane

@serhiy-storchaka serhiy-storchaka added type-bug An unexpected behavior, bug, or error 3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels Oct 13, 2024
@serhiy-storchaka serhiy-storchaka changed the title locale.nl_langinfo(locale.ALT_DIGITS) is broken locale.nl_langinfo(locale.ERA) is broken Oct 14, 2024
@serhiy-storchaka
Copy link
Member Author

@kulikjak, could you also show the output of the above code on Solaris?

@kulikjak
Copy link
Contributor

Sure, here's the output:

ja_JP.PCK +:2:2020/01/01:+*:令和:%EC%Ey年;+:1:2019/05/01:2019/12/31:令和:%EC元年;+:2:1990/01/01:2019/04/30:平成:%EC%Ey年;+:1:1989/01/08:1989/12/31:平成:%EC元年;+:2:1927/01/01:1989/01/07:昭和:%EC%Ey年
ja_JP.UTF-8 +:2:2020/01/01:+*:令和:%EC%Ey年;+:1:2019/05/01:2019/12/31:令和:%EC元年;+:2:1990/01/01:2019/04/30:平成:%EC%Ey年;+:1:1989/01/08:1989/12/31:平成:%EC元年;+:2:1927/01/01:1989/01/07:昭和:%EC%Ey年
ja_JP.eucJP +:2:2020/01/01:+*:令和:%EC%Ey年;+:1:2019/05/01:2019/12/31:令和:%EC元年;+:2:1990/01/01:2019/04/30:平成:%EC%Ey年;+:1:1989/01/08:1989/12/31:平成:%EC元年;+:2:1927/01/01:1989/01/07:昭和:%EC%Ey年
th_TH.TIS620 +:0:-543/01/01:+*::พ.ศ. %Ey
zh_CN.GB18030 +:0:0000/01/01:+*:公元:%EC%Ey年;+:1:-0001/12/31:-*:公元前:%EC%Ey年

(sorry I didn't notice this yesterday)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes type-bug An unexpected behavior, bug, or error
Projects
Status: Todo
Development

No branches or pull requests

2 participants