[ python-Bugs-951235 ] strptime doesn't account for %p in output

SourceForge.net noreply at sourceforge.net
Mon May 10 21:15:56 EDT 2004


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

Category: Python Library
Group: None
Status: Closed
Resolution: Invalid
Priority: 5
Submitted By: Skip Montanaro (montanaro)
Assigned to: Brett Cannon (bcannon)
Summary: strptime doesn't account for %p in output

Initial Comment:
Correct use of the "%p" format is not obvious:

    >>> time.strptime("3:15pm", '%H:%M%p')
    (1900, 1, 1, 3, 15, 0, 0, 1, -1)
    >>> time.strptime("3:15", '%H:%M')
    (1900, 1, 1, 3, 15, 0, 0, 1, -1)
    >>> time.strptime("3:15am", '%H:%M%p')
    (1900, 1, 1, 3, 15, 0, 0, 1, -1)

Other than successfully parsing 'am' or 'pm', there's no
indication in the returned time tuple of a 12-hour
offset in
the 'pm' case.  I think the hour field returned from
the first call
should be 15, not 3.


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

>Comment By: Brett Cannon (bcannon)
Date: 2004-05-10 18:15

Message:
Logged In: YES 
user_id=357491

Yep, works for me.  Thanks, Skip.

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

Comment By: Skip Montanaro (montanaro)
Date: 2004-05-10 11:54

Message:
Logged In: YES 
user_id=44345

I checked in a change to Doc/lib/libtime.tex (v. 1.64).  See
if that seems correct to you.


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

Comment By: Brett Cannon (bcannon)
Date: 2004-05-10 11:19

Message:
Logged In: YES 
user_id=357491

It's a misuse of %H.  If you look at the 'time' module docs (http://
docs.python.org/lib/module-time.html so you don't have to click to it), it 
states %H is "Hour (24-hour clock) as a decimal number" while %I is 
"Hour (12-hour clock) as a decimal number".  Use of %p is only 
triggered when %I is used since otherwise it is not supposed to be 
needed.

This also deals with your corner case, Skip.

If you feel this should be handled another way, let me know.  But since 
putting in extra info that is not used is not against the rules, the code 
just doesn't bother using %p information unless %I is used.  I guess I 
could raise an exception, but that seems harsh.  Could do a warning, but 
not sure if that is the right way to go either.

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

Comment By: Skip Montanaro (montanaro)
Date: 2004-05-10 06:21

Message:
Logged In: YES 
user_id=44345

Another corner case involving am/pm:

>>> time.strptime("15:15pm", '%H:%M%p')
(1900, 1, 1, 15, 15, 0, 0, 1, -1)
>>> time.strptime("15:15am", '%H:%M%p')
(1900, 1, 1, 15, 15, 0, 0, 1, -1)

Shouldn't both raise ValueError since the input hour was not
< 13?


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

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



More information about the Python-bugs-list mailing list