The short names for time zones are not globally unique. The most you can
expect from them is for the short names of the local time zones to be
different for DST and non-DST and distinct from UTC/GMT.

I’m not even sure if they are guaranteed to be different from the US time
zone names which are often hard-wired for legacy support (e.g. in
email/_parseaddr.py for rfc2822 timestamps).

On Sun, 24 Apr 2022 at 6:41 Eugene Triguba <[email protected]> wrote:

> 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/
>
_______________________________________________
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/

Reply via email to