[issue22377] %Z in strptime doesn't match EST and others

Alexander Belopolsky report at bugs.python.org
Mon Oct 29 13:13:09 EDT 2018


Alexander Belopolsky <alexander.belopolsky at gmail.com> added the comment:

I think strptime should only accept %Z when it comes together with %z and not do any validation.

This is close to the current behavior.  %Z by itself is useless because even when it is accepted, the value is discarded:

>>> print(datetime.strptime('UTC', '%Z'))
1900-01-01 00:00:00

You have to use %z to get an aware datetime instance: 

>>> print(datetime.strptime('UTC+0000', '%Z%z'))
1900-01-01 00:00:00+00:00


The validation is already fairly lax:

>>> print(datetime.strptime('UTC+1234', '%Z%z'))
1900-01-01 00:00:00+12:34

I don't think this issue has anything to do with the availability of zoneinfo database.  Timezone abbreviations are often ambiguous and should only serve as a human-readable supplement to the UTC offset and cannot by itself be used as a TZ specification.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue22377>
_______________________________________


More information about the Python-bugs-list mailing list