Looking for comments on changing strptime(3) %p behavior
Brian Ginsbach <ginsbach <at> netbsd.org>
2015-05-01 19:41:00 GMT
The current behavior of strptime(3) and the %p format specifier is
a bit inconsistent/counter-intuitive/surprising. The results aren't
always what one would expect. Nor what is seen from other strptime(3)
implementations. Looking for feedback on the following.
a. strptime(str, "%H %p", &tm)
Currently if str contains 0-11, for the hour, and a am/pm string
the time will be adjusted accordingly. However if the str
contains 12-23, for the hour, and a am/pm string strptime(3)
returns NULL (error). This seems inconsistent if not a bug.
Does it make sense to apply %p to any hour parsed by %H (or %k)
as %H implies a 24-hour clock value? The current code is
inconsistent; %p is valid with 0-11 while %p is invalid with
12-23 (strptime(3) returns NULL). The tm_hour is only adjusted
when %pm is PM and < 11.
Would a more consistent approach would be to not apply %p to
any 24-hour clock value? It doesn't necessarily make sense that
%H (24-hour clock) with %p should be an error regardless of the
value parsed. The %p would be parsed but ignored when combined
with a 24-hour clock.
b. strptime(str, "%p", &tm)
Currently if str contains a am/pm string and no hour is specified
then tm_hour is adjusted as per above or an error is returned
based on tm_hour. This would seem to be a bug on both counts.