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