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 bug in time module
Type: Stage:
Components: Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: brett.cannon, embirath, nnorwitz
Priority: normal Keywords:

Created on 2007-06-03 21:27 by embirath, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg32198 - (view) Author: Emma (embirath) Date: 2007-06-03 21:27
The strptime function takes 2 arguments:
(1) a time string (like "2007 Jan 17, 10:00"), and
(2) a time format string (like "%Y %b %d, %H:%M")

Normally, a ValueError will be raised when the time string does not match the format string. The bug I have found is that NO ValueError is raised in the case below. Instead, and incorrect date is returned (Jan 18th is returned, when really June 29th should be returned).

> from time import *
> print strptime('2007-180', '%Y-%j %H')
msg32199 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2007-06-03 21:33
Brett, could you take a look?  I think this is your code.  I verified this on head, but assume 2.5 has the problem.
msg32200 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2007-06-03 22:43
Found the problem.  The regex being compiled is using ``\s*`` for the space separator.  So when you match against '2007-180' it is matching %Y fine, but it matches %j to 18 and %H to 0 in order to make the regex match.  Changing the regex creation algorithm to use ``\s+`` solved the problem.

I am running the test suite now to make sure this doesn't break anything.  Once its done (assuming it passes) I will commit and backport to 2.5.
msg32201 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2007-06-04 00:14
Committed in r55752 on the trunk and r55753 in 2.5.
History
Date User Action Args
2022-04-11 14:56:24adminsetgithub: 45031
2007-06-03 21:27:05embirathcreate