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: no %z directive for strptime in python2, doc says nothing about it
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: deronnax, r.david.murray
Priority: normal Keywords:

Created on 2017-03-02 07:31 by deronnax, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg288782 - (view) Author: Mathieu Dupuy (deronnax) * Date: 2017-03-02 07:31
➜  ~ cat dt.py 
from datetime import *
dt = datetime.strptime('+1720', '%z')
print(dt)
➜  ~ python2 dt.py 
Traceback (most recent call last):
  File "dt.py", line 2, in <module>
    dt = datetime.strptime('+1720', '%z')
  File "/usr/lib/python2.7/_strptime.py", line 324, in _strptime
    (bad_directive, format))
ValueError: 'z' is a bad directive in format '%z'
➜  ~ python3 dt.py
1900-01-01 00:00:00+17:20

We should either mention it in doc, either cherry-pick the code from python3
msg288800 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-03-02 13:35
This almost qualifies as a FAQ :)

In 2.7 (and in 3.x, though we've added some additional platform independent stuff there), strptime supports what the platform supports, and this is documented: "The following is a list of all the format codes that the C standard (1989 version) requires, and these work on all platforms with a standard C implementation. Note that the 1999 version of the C standard added additional format codes."

Windows, for one, is not a standard C implementation in that sense.

Note that the python3 documentation is a bit clearer about this than the 2.7 docs.  If you want to open a PR to backport the doc improvements, feel free to reopen this issue.
msg289069 - (view) Author: Mathieu Dupuy (deronnax) * Date: 2017-03-06 07:32
Neither documentation is clear on whether each of those flags are available for strptime too. A precision should be added on a flag if it's not available for strptime. What do you think ?
History
Date User Action Args
2022-04-11 14:58:43adminsetgithub: 73876
2017-03-06 07:32:14deronnaxsetmessages: + msg289069
2017-03-02 13:36:00r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg288800

resolution: not a bug
stage: resolved
2017-03-02 07:31:29deronnaxcreate