classification
Title: strptime not parsing some timezones
Type: behavior Stage:
Components: Documentation Versions: Python 3.6, Python 3.5, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: belopolsky, brett.cannon, docs@python, martin.panter, r.david.murray, utkonos
Priority: normal Keywords:

Created on 2015-12-28 08:32 by utkonos, last changed 2016-01-01 20:24 by r.david.murray.

Messages (3)
msg257108 - (view) Author: Utkonos (utkonos) Date: 2015-12-28 08:32
I get a ValueError when running the following through strptime:

datetime.datetime.strptime('(CST)', '(%Z)')

But the following works:
datetime.datetime.strptime('(EST)', '(%Z)')

PST and MST also trigger the same exception.
msg257262 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-01-01 02:11
I suspect the datetime module’s %Z parsing depends on the locale, just like time.strptime() does: <https://docs.python.org/dev/library/time.html#time.strptime>.
msg257294 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-01-01 20:24
The code is shared by the two modules (it's in _strptime.py).  So, yes.

There is clearly a doc bug here (%Z needs a footnote in the table in the datetime docs), but there is no practical way to implement the parsing of arbitrary (non-locale) timezone strings, since it is not a one-to-one mapping.
History
Date User Action Args
2016-01-01 20:24:03r.david.murraysetversions: + Python 2.7, Python 3.6
nosy: + r.david.murray, docs@python

messages: + msg257294

assignee: docs@python
components: + Documentation
2016-01-01 02:11:19martin.pantersetnosy: + martin.panter
messages: + msg257262
2015-12-28 08:32:13utkonoscreate