-
-
Notifications
You must be signed in to change notification settings - Fork 31k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
datetime.strftime("%Y")
is not padding correctly
#120713
Comments
Reproducible on 3.10 but not on 3.11+. |
cc @pganssle I suppose that it works in such way since Python 3.0 (I tested in 3.3). 2.7 does not support years before 1900. You can use %4Y to always get 4-digit year. I wonder whether this is a documentation issue or the output is platform depending. |
Ah, so the issue is platform-dependent. When I reproduced the OP's issue in 3.10 I was doing it in Linux, while in Windows I tested the code in 3.11 and 3.13 and the issue was not reproduced. Now I realized that this is just a result of According to the doc:
|
The limitation for year >= 1000 was removed in bpo-11930 (gh-56139). But there were various problems with the newly added test For now, we cannot guarantee the result for %Y (and %G) with year < 1000. It is especially bad since |
Since |
Yes, but the problem is that %4Y is a glibc extension. There are platforms that return non-4-digit number and do not support %4Y. If we are going to guarantee 4 digits, the workaround may be much more complex. |
With PR #120820 I've made sure that the translation is only used when explicitly supported by the platform so that it is at least an improvement and not a regression in any case. I did just revert my changes to the unit test to allow an outlier platform to pass the test. |
…acing the specifier with "%4Y"
On second thought, guaranteeing 4 digits is actually not complex since we can simply format the year with I've updated the PR accordingly so that a 4-digit year with century can now be guaranteed. |
… to maximum of long
Good point. I've updated the PR to account for |
…ythonGH-120820) (cherry picked from commit 6d34938) Co-authored-by: blhsing <blhsing@gmail.com>
…time (pythonGH-120820) (cherry picked from commit 6d34938) Co-authored-by: blhsing <blhsing@gmail.com>
…ime.strftime (pythonGH-120820) (pythonGH-121144)" This reverts commit 009618f.
…ime.strftime (pythonGH-120820) (pythonGH-121145)" This reverts commit 027902b.
@serhiy-storchaka @blhsing I'm not sure why but we are seeing failures on JIT for the |
Thanks for the heads-up. It is weird indeed that this can happen since according to the build log the configure script did detect that the platform would not 0-pad a century so the handler for Since this happens only on Will try debugging this on a Mac later.
It's a bug fix but was found to be incomplete, due to issue #122272. |
Please open a new issue and provide more details. |
See #123681. |
Bug report
Bug description:
docs say:
but this is what is happening
CPython versions tested on:
3.10
Operating systems tested on:
No response
Linked PRs
The text was updated successfully, but these errors were encountered: