| Summary: | strptime(3) %d format specifier not completely documented | ||
|---|---|---|---|
| Product: | Documentation | Reporter: | Ronald F. Guilmette <rfg> |
| Component: | Books & Articles | Assignee: | 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
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>
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
State Changed From-To: open->feedback Switch to feedback, this doesn't appear to be a bug and I'll ask Tim about it. Responsible Changed From-To: freebsd-doc->trhodes Over to me for now. State Changed From-To: feedback->closed Closed. This is not a bug. |