]> granicus.if.org Git - icinga2/commitdiff
Fix incorrect week day calculation in LegacyTimePeriod::ParseTimeSpec
authorGunnar Beutner <gunnar@beutner.name>
Sat, 20 Dec 2014 21:04:24 +0000 (22:04 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Sat, 20 Dec 2014 21:04:24 +0000 (22:04 +0100)
fixes #6943

lib/icinga/legacytimeperiod.cpp
lib/icinga/scheduleddowntime.cpp

index fa58c100f1d7e729c4c619097bf9115de0860739..e2f3aa119668fbd7d63a5fb650cf6b78b992a97c 100644 (file)
@@ -234,7 +234,7 @@ void LegacyTimePeriod::ParseTimeSpec(const String& timespec, tm *begin, tm *end,
                        if (tokens.size() > 1)
                                FindNthWeekday(wday, n, begin);
                        else
-                               begin->tm_mday += - begin->tm_wday + wday;
+                               begin->tm_mday += (7 - begin->tm_wday + wday) % 7;
 
                        begin->tm_hour = 0;
                        begin->tm_min = 0;
@@ -247,7 +247,7 @@ void LegacyTimePeriod::ParseTimeSpec(const String& timespec, tm *begin, tm *end,
                        if (tokens.size() > 1)
                                FindNthWeekday(wday, n, end);
                        else
-                               end->tm_mday += - end->tm_wday + wday;
+                               end->tm_mday += (7 - end->tm_wday + wday) % 7;
 
                        end->tm_hour = 0;
                        end->tm_min = 0;
index a1f9492bf87147c15ca8a07099f3007196055ace..e86015ea02dc33fb0da1e7fd714449573b2d717c 100644 (file)
@@ -114,11 +114,17 @@ std::pair<double, double> ScheduledDowntime::FindNextSegment(void)
 
        ObjectLock olock(ranges);
        BOOST_FOREACH(const Dictionary::Pair& kv, ranges) {
+               Log(LogDebug, "ScheduledDowntime")
+                   << "Evaluating segment: " << kv.first << ": " << kv.second << " at ";
+
                Dictionary::Ptr segment = LegacyTimePeriod::FindNextSegment(kv.first, kv.second, &reference);
 
                if (!segment)
                        continue;
 
+               Log(LogDebug, "ScheduledDowntime")
+                   << "Considering segment: " << Utility::FormatDateTime("%c", segment->Get("begin")) << " -> " << Utility::FormatDateTime("%c", segment->Get("end"));
+
                double begin = segment->Get("begin");
 
                if (begin < now)