Skip to content

gh-120713: normalize year with century for datetime.strftime#120820

Merged
serhiy-storchaka merged 56 commits intopython:mainfrom
blhsing:normalize-datetime-strftime-year-with-century
Jun 29, 2024
Merged

gh-120713: normalize year with century for datetime.strftime#120820
serhiy-storchaka merged 56 commits intopython:mainfrom
blhsing:normalize-datetime-strftime-year-with-century

Conversation

@blhsing
Copy link
Contributor

@blhsing blhsing commented Jun 21, 2024

On some platforms such as Linux, datetime.strftime does not 0-pad a year <= 999 when formatting with '%Y' despite the documentation claiming an example output of "0001, 0002, …". The same issue applies when formatting with "%G".

This PR fixes the issue by formatting a year with century with '%04ld' using sprintf (in C) or '{:04}' using str.format (in Python) if the platform is found to show the aforementioned behavior.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants