Comments (7)
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.
from cpython.
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 datetime.strftime
being a thin wrapper over the platform's strftime
in the C library:
According to the doc:
The full set of format codes supported varies across platforms, because Python calls the platform C library’s
strftime()
function, and platform variations are common. To see the full set of format codes supported on your platform, consult thestrftime(3)
documentation.
from cpython.
Reproducible on 3.10 but not on 3.11+.
from cpython.
The limitation for year >= 1000 was removed in bpo-11930 (gh-56139). But there were various problems with the newly added test test_strftime_y2k
, it required several corrections.
For now, we cannot guarantee the result for %Y (and %G) with year < 1000. It is especially bad since strptime()
requires the year to be 4 digits.
from cpython.
Since datetime.strftime
already uses a wrapper function to handle format specifiers not conforming to the C strftime
, I think a reasonable fix would be to add the translation of %Y
to %4Y
there as needed by the platform to make the function portable.
from cpython.
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.
from cpython.
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.
from cpython.
Related Issues (20)
- Simplify chained comparison HOT 2
- Inconsistent behavior of `asyncio.Server.wait_closed` in Python 3.12 versus earlier releases HOT 1
- How does Python's Binascii.a2b_base64 (base64.b64decode) work? HOT 1
- 3.12.4 breaks`logging.config.DictConfig` with `logging.handlers.QueueHandler` on read-only file systems
- Add tests for new Tk widget options
- [RFE] `fields` and `time_*` properties must not be used on UUIDs that are time-agnostic. HOT 6
- [C API] Add PyObject_VectorcallDict() to the limited C API HOT 1
- shutil's move function fails to handle files opened by another process
- Texto HOT 4
- Intel vPro® Platform TEI Study by Forrester
- Bump the bundled pip version to 24.1
- Git for Administrators - MoodleDocs HOT 2
- V20.14.0 HOT 1
- Typo in `urllib.parse` docs: Incorrect parameter name
- Generator store recall HOT 1
- Incoming.md
- Freethreading interpreter will attempt to import unsupported stable ABI extension modules HOT 4
- `FrameLocalsProxy` is stricter than `dict` about what constitutes a match HOT 4
- lgtm/
- ValueError in importlib.metadata for eggs with files installed outside the site packages
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cpython.