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.

Author heidar.rafn
Recipients heidar.rafn
Date 2011-09-02.14:33:26
SpamBayes Score 1.4988011e-15
Marked as misclassified No
Message-id <1314974007.55.0.285568781981.issue12886@psf.upfronthosting.co.za>
In-reply-to
Content
When using datetime.strptime or time.strptime to parse string representing timestamp with the format string '%Y%m%dT%H%M%S' then a strange behavior happens when the input string does not contain the seconds: the minute part is split and first digit used as minutes and second digit as seconds !

According to documentation %M shall contain Minute as a decimal number [00,59] and %S shall contain Second as a decimal number [00,61]

Here are few examples to show this:
------------------
Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.datetime.strptime('20110817T1234','%Y%m%dT%H%M%S')
datetime.datetime(2011, 8, 17, 12, 3, 4)
=>ERROR no seconds in input string: minute=3, second=4
=>I would expect exception ValueError or datetime.datetime(2011, 8, 17, 12, 34, 00)

>>> datetime.datetime.strptime('20110817T123456','%Y%m%dT%H%M%S')
datetime.datetime(2011, 8, 17, 12, 34, 56)
=>CORRECT

>>> datetime.datetime.strptime('20110817T123456','%Y%m%dT%H%M')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/_strptime.py", line 328, in _strptime
    data_string[found.end():])
ValueError: unconverted data remains: 56
=>CORRECT

>>> datetime.datetime.strptime('20110817T1234','%Y%m%dT%H%M')
datetime.datetime(2011, 8, 17, 12, 34)
=> CORRECT

------------------
I have tested this with python 2.6 and 2.7
This also happens on when playing with %H%M format string and omit minutes from the input.
History
Date User Action Args
2011-09-02 14:33:27heidar.rafnsetrecipients: + heidar.rafn
2011-09-02 14:33:27heidar.rafnsetmessageid: <1314974007.55.0.285568781981.issue12886@psf.upfronthosting.co.za>
2011-09-02 14:33:26heidar.rafnlinkissue12886 messages
2011-09-02 14:33:26heidar.rafncreate