[ python-Bugs-1730389 ] strptime bug in time module

SourceForge.net noreply at sourceforge.net
Mon Jun 4 02:14:20 CEST 2007


Bugs item #1730389, was opened at 2007-06-03 14:27
Message generated for change (Comment added) made by bcannon
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1730389&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.5
>Status: Closed
>Resolution: Fixed
Priority: 5
Private: No
Submitted By: Emma (embirath)
Assigned to: Brett Cannon (bcannon)
Summary: strptime bug in time module

Initial Comment:
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')

----------------------------------------------------------------------

>Comment By: Brett Cannon (bcannon)
Date: 2007-06-03 17:14

Message:
Logged In: YES 
user_id=357491
Originator: NO

Committed in r55752 on the trunk and r55753 in 2.5.

----------------------------------------------------------------------

Comment By: Brett Cannon (bcannon)
Date: 2007-06-03 15:43

Message:
Logged In: YES 
user_id=357491
Originator: NO

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.

----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2007-06-03 14:33

Message:
Logged In: YES 
user_id=33168
Originator: NO

Brett, could you take a look?  I think this is your code.  I verified this
on head, but assume 2.5 has the problem.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1730389&group_id=5470


More information about the Python-bugs-list mailing list