`date.strftime` and `datetime.strftime` format dates wrong in some locales.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug report
Bug description:
date.strftime and datetime.strftime format dates wrong in some locales. For example, when the locale is Bulgaria the '%A' format string returns an incorrect value.
>>> locale.setlocale(locale.LC_TIME, 'bg') # 'bg' is Bulgaria
>>> date_str = datetime.date(2025, 2, 25).strftime('%A') # %A is locale's day of the week
>>> date_str
'âòîðíèê'
>>> date_str.encode('cp1252').decode('cp1251') # I think we're interpreting a cp1251 string as cp1252
'вторник' # Google tells me this is Tuesday in Bulgarian
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue on Windows using date.strftime and datetime.strftime with the Bulgarian locale, checking both the %A and %x format strings. Trace how these entry points obtain locale-formatted text and verify that the result is the correctly decoded Bulgarian value rather than mojibake.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- localization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100