-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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
date.strftime
and datetime.strftime
format dates wrong in some locales.
#130528
Comments
This comment has been minimized.
This comment has been minimized.
Ok, second question. I think what's being returned with @serhiy-storchaka you're more of an expert in this case, is it the expected behaviour? namely, should we expect the caller to actually perform the encode/decode themselves or is it something that's wrong with datetime? |
I think |
Oh-oh, it is yet one issue similar to #69998 and bpo-28604. The workaround at he user side is to set LC_CTYPE to the same value as LC_TIME. We can fix this at Python side, but at the cost of making |
I reproduce your case on Linux, so first of all, if you don't have locale (you can check it with >>> locale.setlocale(locale.LC_TIME, 'ka_GE.utf8')
'ka_GE.utf8'
>>> datetime.date(2025, 2, 25).strftime('%A')
'სამშაბათი' # Tuesday
>>> locale.setlocale(locale.LC_TIME, 'ka_GE')
Traceback (most recent call last):
File "<python-input-8>", line 1, in <module>
locale.setlocale(locale.LC_TIME, 'ka_GE')
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
File "./lib/python3.13/locale.py", line 615, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting (I checked the behavior on the |
>>> locale.setlocale(locale.LC_TIME, 'bg_BG')
'bg_BG'
>>> print(datetime.date(2025, 2, 25).strftime('%A'))
вторник
>>> locale.setlocale(locale.LC_TIME, 'bg_BG.UTF-8')
'bg_BG.UTF-8'
>>> print(datetime.date(2025, 2, 25).strftime('%A'))
вторник
>>> locale.setlocale(locale.LC_TIME, 'bg_BG.cp1251')
'bg_BG.cp1251'
>>> print(datetime.date(2025, 2, 25).strftime('%A'))
вторник Unable to reproduce on Linux, maybe this has something to do with how Windows is configured? That seems to be the case for other similar issues. |
Bug report
Bug description:
date.strftime
anddatetime.strftime
format dates wrong in some locales. For example, when the locale is Bulgaria the '%A' format string returns an incorrect value.This also fails with the '%x' format string
I've only tested this on Windows.
My guess is that CPython is making a narrow character API call and using the wrong code page. It should be using the wide character call instead.
CPython versions tested on:
3.13
Operating systems tested on:
Windows
The text was updated successfully, but these errors were encountered: