[OpenAFS-devel] Re: [OpenAFS] vos: failed to parse date...

Jim Rees rees@umich.edu
Thu, 30 Mar 2006 18:16:04 -0500


Moving this from -info to -devel, where it belongs.

Just to get this discussion going again, here is a proposed patch to
util/ktime.c that implements part of Russ's proposal.  I used scanf instead
of strptime, because it works just as well and no one came up with a free
implementation of strptime.  I left out timezone, not because I don't think
it's important, but because I'm lazy and I'm hoping someone else will do
that part.

Does anyone know why the old code is so convoluted?

Comments please.

Index: ktime.c
===================================================================
RCS file: /cvs/openafs/src/util/ktime.c,v
retrieving revision 1.11
diff -u -r1.11 ktime.c
--- ktime.c	8 Sep 2004 21:35:53 -0000	1.11
+++ ktime.c	30 Mar 2006 23:10:37 -0000
@@ -517,6 +517,7 @@
     if (akdate->mask)
 	return 0;
 
+    /* Old ambiguous mm/dd/yy hh:mm:ss format */
 
     code =
 	sscanf(adate, "%d / %d / %d %d : %d : %d%1s", &month, &day2, &year,
@@ -528,13 +529,28 @@
 		   &hour, &min, &c[0]);
 	if (code != 5) {
 	    hour = min = 0;
-	    code = sscanf(adate, "%d / %d / %d%1s", &month, &day2, &year, &c[0]);
+	    code =
+		sscanf(adate, "%d / %d / %d%1s", &month, &day2, &year, &c[0]);
 	    if (code != 3) {
-		return -1;
+		code = -1;
 	    }
 	}
     }
 
+    /* New ISO 8601 (subset) method */
+
+    if (code < 0) {
+	hour = min = sec = 0;
+	code =
+	    sscanf(adate, "%d - %d - %d %d : %d : %d", &year, &month, &day2,
+		   &hour, &min, &sec);
+	if (code < 3)
+	    code = -1;
+    }
+
+    if (code < 0)
+	return code;
+
     if ((year < 0) || (month < 1) || (month > 12) || (day2 < 1) || (day2 > 31) ||	/* more or less */
 	(hour < 0) || (hour > 23) || (min < 0) || (min > 59) || (sec < 0)
 	|| (sec > 59))