Andreas Thienemann afedbd
This patch should resolve some problems with handling of am/pm
Andreas Thienemann afedbd
in schedules as reported by bug #808.
Andreas Thienemann afedbd
Andreas Thienemann afedbd
According to the NIST (US National Institute of Standards and Technology),
Andreas Thienemann afedbd
12am and 12pm are ambiguous and can be defined to anything.  However,
Andreas Thienemann afedbd
12:01am is the same as 00:01 and 12:01pm is the same as 12:01, so Bacula
Andreas Thienemann afedbd
defines 12am as 00:00 (midnight) and 12pm as 12:00 (noon).  You can avoid
Andreas Thienemann afedbd
this abiguity (confusion) by using 24 hour time specifications (i.e.  no
Andreas Thienemann afedbd
am/pm). This is the definition in Bacula version 2.0.3 and later.
Andreas Thienemann afedbd
Andreas Thienemann afedbd
Apply it to version 2.0.3 with:
Andreas Thienemann afedbd
Andreas Thienemann afedbd
  cd <bacula-source>
Andreas Thienemann afedbd
  patch -p0 <2.0.3-ampm.patch
Andreas Thienemann afedbd
  make
Andreas Thienemann afedbd
  ...
Andreas Thienemann afedbd
  make install
Andreas Thienemann afedbd
Andreas Thienemann afedbd
Index: src/dird/run_conf.c
Andreas Thienemann afedbd
===================================================================
Andreas Thienemann afedbd
--- src/dird/run_conf.c	(revision 4349)
Andreas Thienemann afedbd
+++ src/dird/run_conf.c	(working copy)
Andreas Thienemann afedbd
@@ -339,6 +339,7 @@
Andreas Thienemann afedbd
    for ( ; token != T_EOL; (token = lex_get_token(lc, T_ALL))) {
Andreas Thienemann afedbd
       int len; 
Andreas Thienemann afedbd
       bool pm = false;
Andreas Thienemann afedbd
+      bool am = false;
Andreas Thienemann afedbd
       switch (token) {
Andreas Thienemann afedbd
       case T_NUMBER:
Andreas Thienemann afedbd
          state = s_mday;
Andreas Thienemann afedbd
@@ -434,6 +435,7 @@
Andreas Thienemann afedbd
          if (!have_hour) {
Andreas Thienemann afedbd
             clear_bits(0, 23, lrun.hour);
Andreas Thienemann afedbd
          }
Andreas Thienemann afedbd
+//       Dmsg1(000, "s_time=%s\n", lc->str);
Andreas Thienemann afedbd
          p = strchr(lc->str, ':');
Andreas Thienemann afedbd
          if (!p)  {
Andreas Thienemann afedbd
             scan_err0(lc, _("Time logic error.\n"));
Andreas Thienemann afedbd
@@ -441,20 +443,19 @@
Andreas Thienemann afedbd
          }
Andreas Thienemann afedbd
          *p++ = 0;                 /* separate two halves */
Andreas Thienemann afedbd
          code = atoi(lc->str);     /* pick up hour */
Andreas Thienemann afedbd
+         code2 = atoi(p);          /* pick up minutes */
Andreas Thienemann afedbd
          len = strlen(p);
Andreas Thienemann afedbd
-         if (len > 2 && p[len-1] == 'm') {
Andreas Thienemann afedbd
-            if (p[len-2] == 'a') {
Andreas Thienemann afedbd
-               pm = false;
Andreas Thienemann afedbd
-            } else if (p[len-2] == 'p') {
Andreas Thienemann afedbd
-               pm = true;
Andreas Thienemann afedbd
-            } else {
Andreas Thienemann afedbd
-               scan_err0(lc, _("Bad time specification."));
Andreas Thienemann afedbd
-               /* NOT REACHED */
Andreas Thienemann afedbd
-            }
Andreas Thienemann afedbd
-         } else {
Andreas Thienemann afedbd
-            pm = false;
Andreas Thienemann afedbd
+         if (len >= 2) {
Andreas Thienemann afedbd
+            p += 2;
Andreas Thienemann afedbd
          }
Andreas Thienemann afedbd
-         code2 = atoi(p);             /* pick up minutes */
Andreas Thienemann afedbd
+         if (strcasecmp(p, "pm") == 0) {
Andreas Thienemann afedbd
+            pm = true;
Andreas Thienemann afedbd
+         } else if (strcasecmp(p, "am") == 0) {
Andreas Thienemann afedbd
+            am = true;
Andreas Thienemann afedbd
+         } else if (len != 2) {
Andreas Thienemann afedbd
+            scan_err0(lc, _("Bad time specification."));
Andreas Thienemann afedbd
+            /* NOT REACHED */
Andreas Thienemann afedbd
+         }   
Andreas Thienemann afedbd
          /* 
Andreas Thienemann afedbd
           * Note, according to NIST, 12am and 12pm are ambiguous and
Andreas Thienemann afedbd
           *  can be defined to anything.  However, 12:01am is the same
Andreas Thienemann afedbd
@@ -467,13 +468,14 @@
Andreas Thienemann afedbd
                code += 12;
Andreas Thienemann afedbd
             }
Andreas Thienemann afedbd
          /* am */
Andreas Thienemann afedbd
-         } else if (code == 12) {
Andreas Thienemann afedbd
+         } else if (am && code == 12) {
Andreas Thienemann afedbd
             code -= 12;
Andreas Thienemann afedbd
          }
Andreas Thienemann afedbd
          if (code < 0 || code > 23 || code2 < 0 || code2 > 59) {
Andreas Thienemann afedbd
             scan_err0(lc, _("Bad time specification."));
Andreas Thienemann afedbd
             /* NOT REACHED */
Andreas Thienemann afedbd
          }
Andreas Thienemann afedbd
+//       Dmsg2(000, "hour=%d min=%d\n", code, code2);
Andreas Thienemann afedbd
          set_bit(code, lrun.hour);
Andreas Thienemann afedbd
          lrun.minute = code2;
Andreas Thienemann afedbd
          have_hour = true;