Skip to content

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

Open
@serhiy-storchaka

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

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions