]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/2.0.x/2.0.3-ampm.patch
ebl Update patch for #1190
[bacula/bacula] / bacula / patches / 2.0.x / 2.0.3-ampm.patch
1 This patch should resolve some problems with handling of am/pm
2 in schedules as reported by bug #808.
3
4 According to the NIST (US National Institute of Standards and Technology),
5 12am and 12pm are ambiguous and can be defined to anything.  However,
6 12:01am is the same as 00:01 and 12:01pm is the same as 12:01, so Bacula
7 defines 12am as 00:00 (midnight) and 12pm as 12:00 (noon).  You can avoid
8 this abiguity (confusion) by using 24 hour time specifications (i.e.  no
9 am/pm). This is the definition in Bacula version 2.0.3 and later.
10
11 Apply it to version 2.0.3 with:
12
13   cd <bacula-source>
14   patch -p0 <2.0.3-ampm.patch
15   make
16   ...
17   make install
18
19 Index: src/dird/run_conf.c
20 ===================================================================
21 --- src/dird/run_conf.c (revision 4349)
22 +++ src/dird/run_conf.c (working copy)
23 @@ -339,6 +339,7 @@
24     for ( ; token != T_EOL; (token = lex_get_token(lc, T_ALL))) {
25        int len; 
26        bool pm = false;
27 +      bool am = false;
28        switch (token) {
29        case T_NUMBER:
30           state = s_mday;
31 @@ -434,6 +435,7 @@
32           if (!have_hour) {
33              clear_bits(0, 23, lrun.hour);
34           }
35 +//       Dmsg1(000, "s_time=%s\n", lc->str);
36           p = strchr(lc->str, ':');
37           if (!p)  {
38              scan_err0(lc, _("Time logic error.\n"));
39 @@ -441,20 +443,19 @@
40           }
41           *p++ = 0;                 /* separate two halves */
42           code = atoi(lc->str);     /* pick up hour */
43 +         code2 = atoi(p);          /* pick up minutes */
44           len = strlen(p);
45 -         if (len > 2 && p[len-1] == 'm') {
46 -            if (p[len-2] == 'a') {
47 -               pm = false;
48 -            } else if (p[len-2] == 'p') {
49 -               pm = true;
50 -            } else {
51 -               scan_err0(lc, _("Bad time specification."));
52 -               /* NOT REACHED */
53 -            }
54 -         } else {
55 -            pm = false;
56 +         if (len >= 2) {
57 +            p += 2;
58           }
59 -         code2 = atoi(p);             /* pick up minutes */
60 +         if (strcasecmp(p, "pm") == 0) {
61 +            pm = true;
62 +         } else if (strcasecmp(p, "am") == 0) {
63 +            am = true;
64 +         } else if (len != 2) {
65 +            scan_err0(lc, _("Bad time specification."));
66 +            /* NOT REACHED */
67 +         }   
68           /* 
69            * Note, according to NIST, 12am and 12pm are ambiguous and
70            *  can be defined to anything.  However, 12:01am is the same
71 @@ -467,13 +468,14 @@
72                 code += 12;
73              }
74           /* am */
75 -         } else if (code == 12) {
76 +         } else if (am && code == 12) {
77              code -= 12;
78           }
79           if (code < 0 || code > 23 || code2 < 0 || code2 > 59) {
80              scan_err0(lc, _("Bad time specification."));
81              /* NOT REACHED */
82           }
83 +//       Dmsg2(000, "hour=%d min=%d\n", code, code2);
84           set_bit(code, lrun.hour);
85           lrun.minute = code2;
86           have_hour = true;