Enhancement Proposal: Standardized Support for Non-Zero-Padded Day and Month Formatting in datetime.strftime
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne bei datetime.datetime.strftime und untersuche, wie seine Direktiven von der zugrunde liegenden C-Bibliothek auf Unix-ähnlichen Systemen und unter Windows abhängen. Prüfe die verknüpften PRs, bevor du beginnst; als erledigt gilt die Aufgabe, wenn ein festgelegter, konsistenter Ansatz für die Formatierung von Tagen und Monaten ohne führende Nullen über alle Plattformen hinweg gefunden wurde.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- operating-systems
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 20/100