Title: Inconsistent `datetime.*.strftime()` year padding behavior across `%y`, `%Y`, `%F` and `%C` · Issue #122272 · python/cpython · GitHub
Open Graph Title: Inconsistent `datetime.*.strftime()` year padding behavior across `%y`, `%Y`, `%F` and `%C` · Issue #122272 · python/cpython
X Title: Inconsistent `datetime.*.strftime()` year padding behavior across `%y`, `%Y`, `%F` and `%C` · Issue #122272 · python/cpython
Description: Bug report Bug description: #120713 changed the way %y and %Y format works with strftime() to pad "short" years with leading zeros. However, the %F and %C formats were left alone, creating inconsistency: >>> from datetime import date >>>...
Open Graph Description: Bug report Bug description: #120713 changed the way %y and %Y format works with strftime() to pad "short" years with leading zeros. However, the %F and %C formats were left alone, creating inconsis...
X Description: Bug report Bug description: #120713 changed the way %y and %Y format works with strftime() to pad "short" years with leading zeros. However, the %F and %C formats were left alone, creatin...
Opengraph URL: https://github.com/python/cpython/issues/122272
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inconsistent `datetime.*.strftime()` year padding behavior across `%y`, `%Y`, `%F` and `%C`","articleBody":"# Bug report\r\n\r\n### Bug description:\r\n\r\n#120713 changed the way `%y` and `%Y` format works with `strftime()` to pad \"short\" years with leading zeros. However, the `%F` and `%C` formats were left alone, creating inconsistency:\r\n\r\n```python\r\n\u003e\u003e\u003e from datetime import date\r\n\u003e\u003e\u003e date(909, 9, 9).strftime(\"%Y\")\r\n'0909'\r\n\u003e\u003e\u003e date(909, 9, 9).strftime(\"%y\")\r\n'09'\r\n\u003e\u003e\u003e date(909, 9, 9).strftime(\"%C\")\r\n'9'\r\n\u003e\u003e\u003e date(909, 9, 9).strftime(\"%F\")\r\n'909-09-09'\r\n```\r\n\r\nWhile I don't have a strong opinion about `%C`, the change to `%Y` now means that `%Y-%m-%d` no longer matches `%F`.\r\n\r\nNotably, this change broke the logic in Django that assumed that if `%Y` returns a zero-padded year number, no padding needs to be done for all formats:\r\n\r\nhttps://github.com/django/django/blob/0e94f292cda632153f2b3d9a9037eb0141ae9c2e/django/utils/formats.py#L266-L273\r\n\r\nI will report a bug there as well, but I think it would be beneficial to preserve consistency here.\r\n\r\nDjango bug: https://code.djangoproject.com/ticket/35630\r\n\r\nCC @blhsing @martinvuyk \r\n\r\n### CPython versions tested on:\r\n\r\n3.13, CPython main branch\r\n\r\n### Operating systems tested on:\r\n\r\nLinux\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-122436\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/mgorny","@type":"Person","name":"mgorny"},"datePublished":"2024-07-25T10:38:28.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":21},"url":"https://github.com/122272/cpython/issues/122272"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7fe36fc6-f307-aa16-0f16-ffe71db18a8f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9B3A:189C33:19E9071:21BE34A:696B2FFE |
| html-safe-nonce | 59cd1e61d887090bf6c5e09ed2eda2877050da2be7028de5e64df79506cf5b84 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QjNBOjE4OUMzMzoxOUU5MDcxOjIxQkUzNEE6Njk2QjJGRkUiLCJ2aXNpdG9yX2lkIjoiNzE2MTkwODAzODU3NzM2OTA4NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7c6cea307a77fe06e12b22d43a85d874942f1d7f41139f18931a69ff691a9521 |
| hovercard-subject-tag | issue:2429628937 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/122272/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9069e103d944643d60c45542e8af736b0afc8c5384c28b39bb971d50e32901bc/python/cpython/issues/122272 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9069e103d944643d60c45542e8af736b0afc8c5384c28b39bb971d50e32901bc/python/cpython/issues/122272 |
| og:image:alt | Bug report Bug description: #120713 changed the way %y and %Y format works with strftime() to pad "short" years with leading zeros. However, the %F and %C formats were left alone, creating inconsis... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mgorny |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width