You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It might perform better to use locale.nl_langinfo to get the current locale's datetime information instead of reverse-engineering from strftime (need to benchmark to see if this is true). This would need to be conditional as the datetime info might not be exposed through nl_langinfo.
But there is other issue. Month and weekday names returned by nl_langinfo() and strftime() can be different.
In br_FR locale: "'" vs "ʼ" (U+02BC).
In ast_ES, ca_AD, ca_ES, ca_FR, ca_IT, ca_ES, oc_FR and wa_BE locales: "'" vs "’" (U+2019).
In yi_US locale: "אַ" (U+FB2E) vs "אַ" (U+05D0 U+05B7) and many others.
I suppose this is because strftime() is implemented using wcsftime() if it is available, but nl_langinfo() needs decoding from the current locale encoding. 8-bit encodings (ISO8859-1 for br_FR and ca_FR, CP1255 for yi_US, etc) can replace some Unicode characters with other similarly looking characters.
This issue exists also in the current code: strptime() is not always able to parse string formatted in C or other language or in Python on other platform, even if they support the same locale. strptime() should be more lenient and accept different forms of apostrophes and different form of normalization. This is a different issue, but we cannot just use nl_langinfo() without breaking existing tests until it is fixed.
On glibc platforms we can also use private API to get Unicode result of nl_langinfo(), without using intermediate locale encoding. This may be faster and allows to avoid temporary switching the current locale. This will help also for Python implementation of strftime(). This is also a different issue, but it will help to use nl_langinfo().
There is other issue. On some locales there are different names for months and weekdays, it is not a matter of some normalization:
be_BY.utf8: "чэрвеня" vs "červienia".
tt_RU.utf8: "июнь" vs "yün".
nan_TW@latin: "6goe̍h" vs "六月".
sr_RS@latin: "jun" vs "јун".
ug_CN@latin: "Seper" vs "ئىيۇن".
uz_UZ@cyrillic: "Июн" vs "Iyun".
sd_IN@devanagari: "जूनि" vs "جون".
It seems that the modifier (@latin, @cyrillic, @devanagari) is just ignored in some cases (this is the locale module bug). But I do not know why there is a difference for be_BY.utf8 and tt_RU.utf8.
Activity
brettcannon commentedon Jun 6, 2010
It might perform better to use locale.nl_langinfo to get the current locale's datetime information instead of reverse-engineering from strftime (need to benchmark to see if this is true). This would need to be conditional as the datetime info might not be exposed through nl_langinfo.
abalkin commentedon Jun 10, 2010
See also bpo-8957. If this happens, I would like to add a pure python implementation strftime. See also bpo-7989.
abalkin commentedon Jan 10, 2011
I would also like to consider using OS strptime on platforms with a decent implementation.
StanFromIreland commentedon Mar 16, 2025
Not fully possible,
nl_langinfodoesn't supportLC_TIME.We can partially use it, ~33% faster.
Caching the information will result in a decent performance gain.
StanFromIreland commentedon Mar 16, 2025
This should be a separate issue.
StanFromIreland commentedon Mar 16, 2025
@picnixz _strptime is currently pure python. This does not need the extension-modules label. It does however need the performance label :-)
[-]Use locale.nl_langinfo in _strptime[/-][+]Use locale.nl_langinfo in `_strptime.py`[/+]picnixz commentedon Mar 16, 2025
I never know which part of the date/time API is duplicated in C and which one is not so thanks.
serhiy-storchaka commentedon Jun 28, 2025
nl_langinfo()supportsLC_TIME.But there is other issue. Month and weekday names returned by
nl_langinfo()andstrftime()can be different.'" vs "ʼ" (U+02BC).'" vs "’" (U+2019).אַ" (U+FB2E) vs "אַ" (U+05D0 U+05B7) and many others.I suppose this is because
strftime()is implemented usingwcsftime()if it is available, butnl_langinfo()needs decoding from the current locale encoding. 8-bit encodings (ISO8859-1 for br_FR and ca_FR, CP1255 for yi_US, etc) can replace some Unicode characters with other similarly looking characters.This issue exists also in the current code:
strptime()is not always able to parse string formatted in C or other language or in Python on other platform, even if they support the same locale.strptime()should be more lenient and accept different forms of apostrophes and different form of normalization. This is a different issue, but we cannot just usenl_langinfo()without breaking existing tests until it is fixed.On glibc platforms we can also use private API to get Unicode result of
nl_langinfo(), without using intermediate locale encoding. This may be faster and allows to avoid temporary switching the current locale. This will help also for Python implementation ofstrftime(). This is also a different issue, but it will help to usenl_langinfo().serhiy-storchaka commentedon Jun 28, 2025
There is other issue. On some locales there are different names for months and weekdays, it is not a matter of some normalization:
It seems that the modifier (
@latin,@cyrillic,@devanagari) is just ignored in some cases (this is thelocalemodule bug). But I do not know why there is a difference for be_BY.utf8 and tt_RU.utf8.