Skip to content
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

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

Open
wants to merge 4 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/

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.

1 participant