python / python/cpython

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

Abierto
#137,165 4 comentarios 2 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

extension-modules stdlib type-feature
Lenguaje dominante
Python
Estrellas
77.2k
Forks
35.9k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza en datetime.datetime.strftime e investiga cómo dependen sus directivas de la biblioteca C subyacente en sistemas similares a Unix y Windows. Revisa los PRs enlazados antes de empezar; se considerará terminado cuando se haya decidido un enfoque coherente para formatear los días y meses sin ceros iniciales en todas las plataformas.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
operating-systems
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
20/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.