Skip to content

datetime.strptime is broken with timezones without DST #532

@vytas7

Description

@vytas7

It seems that some datetime.strptime expressions, especially including the timezone (%Z) break in GraalPy:

(graalenv) bash-5.2# python -V && python -c "import datetime; print(datetime.datetime.strptime('Tue, 15 Nov 1994 12:45:26 GMT', '%a, %d %b %Y %H:%M:%S %Z'))"
GraalPy 3.11.7 (GraalVM CE Native 24.2.2)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/opt/graalpy-24.2.2/lib/python3.11/datetime.py", line 2059, in strptime
    return _strptime._strptime_datetime(cls, date_string, format)
  File "/opt/graalpy-24.2.2/lib/python3.11/_strptime.py", line 568, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
  File "/opt/graalpy-24.2.2/lib/python3.11/_strptime.py", line 480, in _strptime
    if (time.tzname[0] == time.tzname[1] and
IndexError: tuple index out of range

Cf vanilla CPython 3.11.7:

root@3133141ae9f2:/# python -V && python -c "import datetime; print(datetime.datetime.strptime('Tue, 15 Nov 1994 12:45:26 GMT', '%a, %d %b %Y %H:%M:%S %Z'))"
Python 3.11.7
1994-11-15 12:45:26

So it doesn't look like a standard library issue, but something else is going on 🤔

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions