[icinga-checkins] icinga.org: icinga2/master: Fix parsing <MONTH> <DAY> time defs (e.g. " december 25").

git at icinga.org git at icinga.org
Fri May 3 12:31:42 CEST 2013


Module: icinga2
Branch: master
Commit: 1e9dcb35b49215dfc1e33841acafb6266a785cca
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=1e9dcb35b49215dfc1e33841acafb6266a785cca

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Fri May  3 12:31:11 2013 +0200

Fix parsing <MONTH> <DAY> time defs (e.g. "december 25").

Fixes #4040

---

 lib/icinga/legacytimeperiod.cpp |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/icinga/legacytimeperiod.cpp b/lib/icinga/legacytimeperiod.cpp
index 4c5390b..8fc8e6b 100644
--- a/lib/icinga/legacytimeperiod.cpp
+++ b/lib/icinga/legacytimeperiod.cpp
@@ -159,11 +159,17 @@ void LegacyTimePeriod::ParseTimeSpec(const String& timespec, tm *begin, tm *end,
 	std::vector<String> tokens;
 	boost::algorithm::split(tokens, timespec, boost::is_any_of(" "));
 
-	if (tokens.size() > 1 && tokens[0] == "day") {
+	int mon;
+
+	if (tokens.size() > 1 && (tokens[0] == "day" || (mon = MonthFromString(tokens[0])) != -1)) {
+		if (mon == -1)
+			mon = reference->tm_mon;
+
 		int mday = Convert::ToLong(tokens[1]);
 
 		if (begin) {
 			*begin = *reference;
+			begin->tm_mon = mon;
 			begin->tm_mday = mday;
 			begin->tm_hour = 0;
 			begin->tm_min = 0;
@@ -178,6 +184,7 @@ void LegacyTimePeriod::ParseTimeSpec(const String& timespec, tm *begin, tm *end,
 
 		if (end) {
 			*end = *reference;
+			end->tm_mon = mon;
 			end->tm_mday = mday;
 			end->tm_hour = 24;
 			end->tm_min = 0;
@@ -199,7 +206,7 @@ void LegacyTimePeriod::ParseTimeSpec(const String& timespec, tm *begin, tm *end,
 		tm myref = *reference;
 
 		if (tokens.size() > 2) {
-			int mon = MonthFromString(tokens[2]);
+			mon = MonthFromString(tokens[2]);
 
 			if (mon == -1)
 				BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid month in time specification: " + timespec));





More information about the icinga-checkins mailing list