Should `strptime`, when passed a %Z format specifier, parse more than just
GMT, UTC, and the local time zone given that we now have the IANA database
in the stdlib via PEP 615 since Python 3.9?
The regex for the %Z specifier appears to come from TimeRE and always has
GMT, UTC, and then the local time zone.
>>> from _strptime import TimeRE
>>> t = TimeRE()
>>> t['Z']
'(?P<Z>cst|gmt|utc|cdt)'
>>> from datetime import datetime
>>> datetime.strptime('2016-12-04 08:00:00 CST', '%Y-%m-%d %H:%M:%S %Z')
datetime.datetime(2016, 12, 4, 8, 0)
>>> datetime.strptime('2016-12-04 08:00:00 CDT', '%Y-%m-%d %H:%M:%S %Z')
datetime.datetime(2016, 12, 4, 8, 0)
>>> datetime.strptime('2016-12-04 08:00:00 UTC', '%Y-%m-%d %H:%M:%S %Z')
datetime.datetime(2016, 12, 4, 8, 0)
>>> datetime.strptime('2016-12-04 08:00:00 GMT', '%Y-%m-%d %H:%M:%S %Z')
datetime.datetime(2016, 12, 4, 8, 0)
>>> datetime.strptime('2016-12-04 08:00:00 EST', '%Y-%m-%d %H:%M:%S %Z')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/home/eugene/src/cpython/Lib/_strptime.py", line 568, in
_strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/home/eugene/src/cpython/Lib/_strptime.py", line 349, in
_strptime
raise ValueError("time data %r does not match format %r" %
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: time data '2016-12-04 08:00:00 EST' does not match format
'%Y-%m-%d %H:%M:%S %Z'
There have been some discussions and issues with regard to this in the past:
- https://github.com/python/cpython/issues/66571
- https://github.com/python/cpython/issues/66616
I was interested in taking a look at this, but I wanted to reach out and
know if it was something that would be desirable and what others' thoughts
were.
Thanks,
Eugene
_______________________________________________
Datetime-SIG mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/datetime-sig.python.org/
The PSF Code of Conduct applies to this mailing list:
https://www.python.org/psf/codeofconduct/