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