This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: strptime not parsing some timezones
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: andrei.avk, belopolsky, docs@python, kj, martin.panter, r.david.murray, utkonos
Priority: normal Keywords:

Created on 2015-12-28 08:32 by utkonos, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
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.
msg399153 - (view) Author: Andrei Kulakov (andrei.avk) * (Python triager) Date: 2021-08-06 21:17
This was fixed so can be closed.

Current datetime docs have a footnote for %Z:

...
strptime() only accepts certain values for %Z:

any value in time.tzname for your machine’s locale

the hard-coded values UTC and GMT
msg401293 - (view) Author: Andrei Kulakov (andrei.avk) * (Python triager) Date: 2021-09-07 15:34
I'm closing this as fixed, the note in datetime docs is here:

https://docs.python.org/3.9/library/datetime.html

(search for 'only accepts', - note 6)
History
Date User Action Args
2022-04-11 14:58:25adminsetgithub: 70151
2021-09-07 15:34:06andrei.avksetstatus: open -> closed

versions: + Python 3.9, - Python 2.7, Python 3.5, Python 3.6
nosy: + kj

messages: + msg401293
resolution: fixed
stage: resolved
2021-08-06 21:17:23andrei.avksetnosy: + andrei.avk
messages: + msg399153
2020-09-11 23:15:47brett.cannonsetnosy: - brett.cannon
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