* lib/parse-duration.h: non-iso form accepts years, months weeks, too
* lib/parse-duration.c: use a switch instead of cascading if's.
Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
+2008-11-17 Bruce Korb <bkorb@gnu.org>
+
+ * lib/parse-duration.h: non-iso form accepts years, months weeks, too
+ * lib/parse-duration.c: use a switch instead of cascading if's.
+
2008-12-29 Eric Blake <ebb9@byu.net>
wchar.h: supply WEOF on Irix 5.3
2008-12-29 Eric Blake <ebb9@byu.net>
wchar.h: supply WEOF on Irix 5.3
time_t
parse_duration (char const * pz)
{
time_t
parse_duration (char const * pz)
{
while (isspace ((unsigned char)*pz))
pz++;
while (isspace ((unsigned char)*pz))
pz++;
- do {
- if (*pz == 'P')
- {
- res = parse_period (pz + 1);
- if (res == BAD_TIME)
- break;
- return res;
- }
-
- if (*pz == 'T')
- {
- res = parse_time (pz + 1);
- if (res == BAD_TIME)
- break;
- return res;
- }
-
- if (! isdigit ((unsigned char)*pz))
- break;
+ switch (*pz)
+ {
+ case 'P':
+ return parse_period (pz + 1);
- res = parse_non_iso8601 (pz);
- if (res != BAD_TIME)
- return res;
+ case 'T':
+ return parse_time (pz + 1);
+ default:
+ if (isdigit ((unsigned char)*pz))
+ return parse_non_iso8601 (pz);
+ errno = EINVAL;
+ return BAD_TIME;
+ }
- the string may contain: NNN d NNN h NNN m NNN s
- This represents NNN days, NNN hours, NNN minutes and NNN seconds.
+ the string may contain: NNN Y NNN M NNN W NNN d NNN h NNN m NNN s
+ This represents NNN years, NNN months, NNN weeks, NNN days, NNN hours,
+ NNN minutes and NNN seconds.
The embeded white space is optional.
These terms must appear in this order.
The embeded white space is optional.
These terms must appear in this order.
+ Case is significant: 'M' is months and 'm' is minutes.
The final "s" is optional.
All of the terms ("NNN" plus designator) are optional.
Minutes and seconds may optionally be represented as NNN:NNN.
The final "s" is optional.
All of the terms ("NNN" plus designator) are optional.
Minutes and seconds may optionally be represented as NNN:NNN.