Bug 28699

Summary: strptime(3) %d format specifier not completely documented
Product: Documentation Reporter: Ronald F. Guilmette <rfg>
Component: Books & ArticlesAssignee: Tom Rhodes <trhodes>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Latest   
Hardware: Any   
OS: Any   

Description Ronald F. Guilmette 2001-07-04 23:40:00 UTC
	The %d format specifier, when supplied as part of the format
	string argument in a call to strptime(3), will match *either*
	a pair of consecutive digit characters (as documented for the
	%d specifier on the strftime(3) man page) *or*, additionally,
	it appears to also be willing to match a single space character
	followed by a single digit character.

	This extended functionality of the %d format specifier, when used
	with the strptime(3) function, is very useful (please don't remove
	it!) but it ought to be documented.

Fix: 

Add a note to the strptime(3) man page saying that %d matches either
	two digits or a space followed by a single digit.
How-To-Repeat: 
	man 3 strptime
	man 3 strftime
Comment 1 Joseph Koshy freebsd_committer freebsd_triage 2001-07-20 12:41:34 UTC
I'm not sure that this isn't a bug.  

`strftime(3)' states that '%d' generates 2 digits numbers in the range
01--31. Coming to `strptime(3)', looking at file 
"src/lib/libc/stdtime/strptime.c":

		...
                case 'd':
                case 'e':
                        /*
                         * The %e specifier is explicitly documented as not
                         * being zero-padded but there is no harm in allowing
                         * such padding.
                         *
                         * XXX The %e specifier may gobble one too many
                         * digits if used incorrectly.
                         */
                        if (!isdigit((unsigned char)*buf))
                                return 0;
		...


We see that '%d' will accept a single digit date ONLY if a preceding format
specifier had gobbled up whitespace before it.  A format specification 
with a leading '%d' will fail to recognize a single digit date.  

We probably need to check that the input to %d is exactly 2 digits long.

Regards, 
Koshy 
<jkoshy@freebsd.org>
Comment 2 Tim J. Robbins 2002-01-13 16:01:26 UTC
strptime(3) does not accept "a space followed by a single digit" for %d.
It chews off up to 2 digits and uses them. It doesn't do anything about
whitespace.

tim@raven$ date -j -f "%d" " 1" +%d
Failed conversion of `` 1'' using format ``%d''
date: illegal time format
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format]


Tim
Comment 3 Tom Rhodes freebsd_committer freebsd_triage 2003-05-07 01:26:56 UTC
State Changed
From-To: open->feedback

Switch to feedback, this doesn't appear to be a bug and I'll ask Tim about it. 


Comment 4 Tom Rhodes freebsd_committer freebsd_triage 2003-05-07 01:26:56 UTC
Responsible Changed
From-To: freebsd-doc->trhodes

Over to me for now.
Comment 5 Tom Rhodes freebsd_committer freebsd_triage 2003-05-08 16:10:02 UTC
State Changed
From-To: feedback->closed

Closed.  This is not a bug.