From cf3298f130a5a50cda4fd7401e366e70a65629e3 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 9 Sep 2013 15:54:19 +0200 Subject: [PATCH] ido: Fix timeperiods with more than one segment. --- lib/ido/timeperioddbobject.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/ido/timeperioddbobject.cpp b/lib/ido/timeperioddbobject.cpp index 28f9f9d44..9037305ea 100644 --- a/lib/ido/timeperioddbobject.cpp +++ b/lib/ido/timeperioddbobject.cpp @@ -97,18 +97,24 @@ void TimePeriodDbObject::OnConfigUpdate(void) } #endif /* _MSC_VER */ - tm begin, end; - LegacyTimePeriod::ProcessTimeRangeRaw(value, &reference, &begin, &end); - - DbQuery query; - query.Table = GetType()->GetTable() + "_timeranges"; - query.Type = DbQueryInsert; - query.Fields = boost::make_shared(); - query.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */ - query.Fields->Set("timeperiod_id", DbValue::FromObjectInsertID(tp)); - query.Fields->Set("day", wday); - query.Fields->Set("start_sec", begin.tm_hour * 3600 + begin.tm_min * 60 + begin.tm_sec); - query.Fields->Set("end_sec", end.tm_hour * 3600 + end.tm_min * 60 + end.tm_sec); - OnQuery(query); + Array::Ptr segments = boost::make_shared(); + LegacyTimePeriod::ProcessTimeRanges(value, &reference, segments); + + BOOST_FOREACH(const Value& vsegment, segments) { + Dictionary::Ptr segment = vsegment; + int begin = segment->Get("begin"); + int end = segment->Get("end"); + + DbQuery query; + query.Table = GetType()->GetTable() + "_timeranges"; + query.Type = DbQueryInsert; + query.Fields = boost::make_shared(); + query.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */ + query.Fields->Set("timeperiod_id", DbValue::FromObjectInsertID(tp)); + query.Fields->Set("day", wday); + query.Fields->Set("start_sec", begin % 86400); + query.Fields->Set("end_sec", end % 86400); + OnQuery(query); + } } } -- 2.40.0