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 8bd92e7c09837bc365a640ef1630338d33d8cd1d..d61634eff7225e54957e63f43d7bcb502c9cd742 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
 2008-12-29  Eric Blake  <ebb9@byu.net>
 
        wchar.h: supply WEOF on Irix 5.3
index 91f5291c5b981a6e36fa3276acbd6a670c8c4ba6..561bd98adb028c039ad37264bf490906ab1a4cf8 100644 (file)
@@ -566,38 +566,24 @@ parse_non_iso8601(cch_t * pz)
 time_t
 parse_duration (char const * pz)
 {
 time_t
 parse_duration (char const * pz)
 {
-  time_t res = 0;
-
   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);
 
 
-  } while (0);
+    default:
+      if (isdigit ((unsigned char)*pz))
+        return parse_non_iso8601 (pz);
 
 
-  return BAD_TIME;
+      errno = EINVAL;
+      return BAD_TIME;
+    }
 }
 
 /*
 }
 
 /*
index fbc732ff39c0e4110713c22970831353174c3b61..beab3cf66bd4d9f0da54a711efe95120d0316d5e 100644 (file)
 
   ==== if it is a digit
 
 
   ==== 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.
   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.