Skip to content

gh-128074: Add support +HH format as time zone in datetime.strptime #130390

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

donBarbos
Copy link
Contributor

@donBarbos donBarbos commented Feb 21, 2025

I made the minute (MM) part optional for time zone.

New behavior:

>>> from datetime import datetime
>>> datetime.strptime("2023-05-25T15:35:05.666+11", "%Y-%m-%dT%H:%M:%S.%f%z")
datetime.datetime(2023, 5, 25, 15, 35, 5, 666000, tzinfo=datetime.timezone(datetime.timedelta(seconds=39600)))

Old behavior:

>>> from datetime import datetime
>>> datetime.strptime("2023-05-25T15:35:05.666+11", "%Y-%m-%dT%H:%M:%S.%f%z")
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    datetime.strptime("2023-05-25T15:35:05.666+11", "%Y-%m-%dT%H:%M:%S.%f%z")
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../cpython/Lib/_strptime.py", line 700, in _strptime_datetime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
                                    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File ".../cpython/Lib/_strptime.py", line 453, in _strptime
    raise ValueError("time data %r does not match format %r" %
                     (data_string, format))
ValueError: time data '2023-05-25T15:35:05.666+11' does not match format '%Y-%m-%dT%H:%M:%S.%f%z'

📚 Documentation preview 📚: https://cpython-previews--130390.org.readthedocs.build/

Copy link
Member

@StanFromIreland StanFromIreland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has conflicts now.

@@ -2609,7 +2609,7 @@ convenience. These parameters all correspond to ISO 8601 date values.
| | Jan 4. | | |
+-----------+--------------------------------+------------------------+-------+
| ``%:z`` | UTC offset in the form | (empty), +00:00, | \(6) |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not implemented? It is not implemented in _strptime at all in fact ... #121237

Copy link
Contributor Author

@donBarbos donBarbos Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so it's better not to touch this part of documentation and change it only in PR that adds support %:z, right?

I also suggest opening a new PR if the author doesn't respond within a couple of weeks (maybe you can add his handler in your comment to ping him:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants