python / python/cpython

`date.strftime` and `datetime.strftime` format dates wrong in some locales.

オープン
#130,528 コメント 9 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

3.13 extension-modules OS-windows stdlib type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

ブルガリア語のロケールで date.strftime と datetime.strftime を使用して Windows 上で問題を再現し、%A と %x の両方のフォーマット文字列を確認します。これらのエントリーポイントがロケールに従ってフォーマットされたテキストをどのように取得するかを追跡し、結果が正しくデコードされたブルガリア語の値であり、文字化けではないことを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
localization
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
42/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。