[issue1100942] Add datetime.time.strptime and datetime.date.strptime

Alexander Belopolsky report at bugs.python.org
Wed Jun 9 17:17:25 CEST 2010


Alexander Belopolsky <belopolsky at users.sourceforge.net> added the comment:

I have updated Amaury's patch for py3k.  I simplified the test for default date values and fixed a documentation nit. (Time fileds are [4:7], not [4:6]).  The result is attached as issue1100942.diff.

Note that date.strptime accepts some time specs and time.strptime accepts some date specs:

>>> time.strptime('1900', '%Y')
datetime.time(0, 0)
>>> date.strptime('00', '%H')
datetime.date(1900, 1, 1)

This matches the proposed documentation, but I am not sure is desirable.  
I am about +0 for making the test more robust by scanning the format string and rejecting date format codes in time.strptime and time format codes in date.  This will also allow better diagnostic messages.  For example, instead of 

>>> date.strptime('01', '%M')
Traceback (most recent call last):
  ..
ValueError: date.strptime value cannot have a time part

we can produce "'%M' is not valid in date format specification."

----------
keywords: +easy, patch
Added file: http://bugs.python.org/file17599/issue1100942.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1100942>
_______________________________________


More information about the Python-bugs-list mailing list