Repository navigation
Conversation
This comment was marked as off-topic.
This comment was marked as off-topic.
| :exc:`DeprecationWarning`. In 3.15 or later we may change this into | ||
| an error or change the default year to a leap year. See :gh:`70647`. | ||
|
|
||
| (11) |
Member
There was a problem hiding this comment.
Is a note here the best place for this?
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
|
This PR is stale because it has been open for 30 days with no activity. |
Mariatta
force-pushed
the
123449-docs-about-dtformat
branch
from
October 19, 2026 19:02
4988071 to
f8937f1
Compare
Documentation build overview
|
Comment on lines
+2748
to
+2754
| .. note:: | ||
| When parsing a string using :meth:`.datetime.strptime` or | ||
| :meth:`.date.strptime`, if more than one directive for the same time unit | ||
| is used, only the last directive is parsed and applied to the resulting | ||
| object. For example, if the format string contains both ``%Y`` and ``%y``, | ||
| like ``%Y%y``, only the last directive in the string (``%y``) determines | ||
| the year of the result. |
Member
There was a problem hiding this comment.
Suggested change
| .. note:: | |
| When parsing a string using :meth:`.datetime.strptime` or | |
| :meth:`.date.strptime`, if more than one directive for the same time unit | |
| is used, only the last directive is parsed and applied to the resulting | |
| object. For example, if the format string contains both ``%Y`` and ``%y``, | |
| like ``%Y%y``, only the last directive in the string (``%y``) determines | |
| the year of the result. | |
| .. note:: | |
| If a :meth:`~.datetime.strptime` format string contains more than | |
| one directive for the same field, for example both ``%Y`` and ``%y``, | |
| every directive must still match the input, but only the value of the | |
| last one is used. For example, parsing ``200099`` with ``%Y%y`` gives | |
| the year 1999. Repeating the same directive, like ``%Y%Y``, raises an error. |
A few little suggestions merged (sorry, it was easier with wrapping this way, feel free to split as you see fit!):
- De-duplicate
strptime. - "only the last directive is parsed": I fear "parsed" is a little misleading, as they do still have to match.
- "same time unit": technically it's not so simple, e.g.
%jalways wins over%ddue to parsing implementation details. - Also suggest adding a concrete example.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📚 Documentation preview 📚: https://cpython-previews--125009.org.readthedocs.build/
datetime.strptimeaccepts incompatible arguments #124549