Skip to content

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

Closed as duplicate
Closed as duplicate

Description

@serhiy-storchaka

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

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    3.12only security fixes
    3.13only security fixes
    3.14bugs and security fixes
    on Oct 13, 2024
  2. changed the title [-]locale.nl_langinfo(locale.ALT_DIGITS) is broken[/-] [+]locale.nl_langinfo(locale.ERA) is broken[/+] on Oct 14, 2024
  3. serhiy-storchaka commented on Oct 16, 2024

    @serhiy-storchaka
    MemberAuthor

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

  4. kulikjak commented on Oct 17, 2024

    @kulikjak
    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)

  5. StanFromIreland commented on Jun 23, 2025

    @StanFromIreland
    Member

    With libc 2.41 I get the following:

    cmn_TW +:2:1913/01/01:+*:民國:%EC%Ey年;+:1:1912/01/01:1912/12/31:民國:%EC元年;+:1:1911/12/31:-*:民前:%EC%Ey年
    hak_TW +:2:1913/01/01:+*:民國:%EC%Ey年;+:1:1912/01/01:1912/12/31:民國:%EC元年;+:1:1911/12/31:-*:民前:%EC%Ey年
    ja_JP +: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年;+:1:1926/12/25:1926/12/31:昭和:%EC元年;+:2:1913/01/01:1926/12/24:大正:%EC%Ey年;+:1:1912/07/30:1912/12/31:大正:%EC元年;+:6:1873/01/01:1912/07/29:明治:%EC%Ey年;+:1:0001/01/01:1872/12/31:西暦:%EC%Ey年;+:1:-0001/12/31:-*:紀元前:%EC%Ey年
    japanese +: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年;+:1:1926/12/25:1926/12/31:昭和:%EC元年;+:2:1913/01/01:1926/12/24:大正:%EC%Ey年;+:1:1912/07/30:1912/12/31:大正:%EC元年;+:6:1873/01/01:1912/07/29:明治:%EC%Ey年;+:1:0001/01/01:1872/12/31:西暦:%EC%Ey年;+:1:-0001/12/31:-*:紀元前:%EC%Ey年
    lo_LA +:1:-543/01/01:+*:ພ.ສ.:%EC %Ey
    lzh_TW +:2:1913/01/01:+*:民國:%EC%Ey年;+:1:1912/01/01:1912/12/31:民國:%EC元年;+:1:1911/12/31:-*:民前:%EC%Ey年
    nan_TW +:2:1913/01/01:+*:民國:%EC%Ey年;+:1:1912/01/01:1912/12/31:民國:%EC元年;+:1:1911/12/31:-*:民前:%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年;+:1:1912/01/01:1912/12/31:民國:%EC元年;+:1:1911/12/31:-*:民前:%EC%Ey年
    

    I presume you had an older version. So do we just want to convert it to return a tuple?

  6. added
    3.15bugs and security fixes
    and removed
    3.12only security fixes
    on Jun 27, 2025
  7. serhiy-storchaka commented on Jul 13, 2025

    @serhiy-storchaka
    MemberAuthor

    I forgot about this issue and created a duplicate issue #126727.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13only security fixes3.14bugs and security fixes3.15bugs and security fixesextension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions