python / python/cpython

Enhancement Proposal: Standardized Support for Non-Zero-Padded Day and Month Formatting in datetime.strftime

Aperta
#137,165 4 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

extension-modules stdlib type-feature
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Feature or enhancement

Proposal:

Python's datetime.datetime.strftime supports formatting directives for dates and times, such as %d for zero-padded days and %m for zero-padded months.
While there are platform-specific ways to get non-zero-padded day (%-d on Unix) or month (%-m), these do not work reliably across all platforms.. Particularly between Unix-like systems and Windows.

from datetime import datetime

dt = datetime(2025, 6, 6)

# On Unix:
dt.strftime("%-d. %-m. %Y")  # '6. 6. 2025'

# On Windows:
dt.strftime("%-d. %-m. %Y")  # Raises ValueError

I understand that strftime relies on the underlying C library for formatting, which is probably why this behavior differs between platforms. That said, if it's not practical to change this at the core level, maybe there could be some kind of wrapper or Python-level normalization to make things more consistent across systems.

Currently this requires a workaround such as usage of .format directly on the datetime object.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs
  • gh-138982
  • gh-139002
  • gh-139088
  • gh-145018

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Parti da datetime.datetime.strftime e analizza in che modo le sue direttive dipendano dalla libreria C sottostante sui sistemi Unix-like e su Windows. Esamina le PRs collegati prima di iniziare; il lavoro sarà completo quando sarà stato deciso un approccio coerente per la formattazione dei giorni e dei mesi senza zeri iniziali su tutte le piattaforme.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
operating-systems
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
20/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.