parse-duration: small doc tweak and coding aesthetics issue.
authorBruce Korb <bkorb@gnu.org>
Mon, 29 Dec 2008 21:00:19 +0000 (22:00 +0100)
committerRalf Wildenhues <Ralf.Wildenhues@gmx.de>
Mon, 29 Dec 2008 21:00:19 +0000 (22:00 +0100)
* 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>
ChangeLog
lib/parse-duration.c
lib/parse-duration.h

index 8bd92e7..d61634e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+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
index 91f5291..561bd98 100644 (file)
@@ -566,38 +566,24 @@ parse_non_iso8601(cch_t * pz)
 time_t
 parse_duration (char const * pz)
 {
-  time_t res = 0;
-
   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);
 
-  } while (0);
+    default:
+      if (isdigit ((unsigned char)*pz))
+        return parse_non_iso8601 (pz);
 
-  return BAD_TIME;
+      errno = EINVAL;
+      return BAD_TIME;
+    }
 }
 
 /*
index fbc732f..beab3cf 100644 (file)
 
   ==== if it is a digit
 
-  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.
+  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.