ido: Use relative timestamps for the timeranges.

This commit is contained in:
Gunnar Beutner 2013-08-09 11:07:55 +02:00
parent 0df4c173c9
commit c34540676e
3 changed files with 19 additions and 21 deletions

View File

@ -329,7 +329,7 @@ bool LegacyTimePeriod::IsInDayDefinition(const String& daydef, tm *reference)
return IsInTimeRange(&begin, &end, stride, reference);
}
Dictionary::Ptr LegacyTimePeriod::ProcessTimeRange(const String& timerange, tm *reference)
void LegacyTimePeriod::ProcessTimeRangeRaw(const String& timerange, tm *reference, tm *begin, tm *end)
{
std::vector<String> times;
@ -349,22 +349,24 @@ Dictionary::Ptr LegacyTimePeriod::ProcessTimeRange(const String& timerange, tm *
if (hd2.size() != 2)
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid time specification: " + times[1]));
*begin = *reference;
begin->tm_sec = 0;
begin->tm_min = Convert::ToLong(hd1[1]);
begin->tm_hour = Convert::ToLong(hd1[0]);
*end = *reference;
end->tm_sec = 0;
end->tm_min = Convert::ToLong(hd2[1]);
end->tm_hour = Convert::ToLong(hd2[0]);
}
Dictionary::Ptr LegacyTimePeriod::ProcessTimeRange(const String& timestamp, tm *reference)
{
tm begin, end;
begin = *reference;
begin.tm_sec = 0;
begin.tm_min = Convert::ToLong(hd1[1]);
begin.tm_hour = Convert::ToLong(hd1[0]);
end = *reference;
end.tm_sec = 0;
end.tm_min = Convert::ToLong(hd2[1]);
end.tm_hour = Convert::ToLong(hd2[0]);
ProcessTimeRangeRaw(timestamp, reference, &begin, &end);
Dictionary::Ptr segment = boost::make_shared<Dictionary>();
segment->Set("begin", (long)mktime(&begin));
segment->Set("end", (long)mktime(&end));
return segment;
}

View File

@ -44,6 +44,7 @@ public:
static void ParseTimeSpec(const String& timespec, tm *begin, tm *end, tm *reference);
static void ParseTimeRange(const String& timerange, tm *begin, tm *end, int *stride, tm *reference);
static bool IsInDayDefinition(const String& daydef, tm *reference);
static void ProcessTimeRangeRaw(const String& timerange, tm *reference, tm *begin, tm *end);
static Dictionary::Ptr ProcessTimeRange(const String& timerange, tm *reference);
static void ProcessTimeRanges(const String& timeranges, tm *reference, const Array::Ptr& result);

View File

@ -97,12 +97,7 @@ void TimePeriodDbObject::OnConfigUpdate(void)
#endif /* _MSC_VER */
tm begin, end;
int stride;
LegacyTimePeriod::ParseTimeRange(key, &begin, &end, &stride, &reference);
if (stride != 1)
continue;
LegacyTimePeriod::ProcessTimeRangeRaw(value, &reference, &begin, &end);
DbQuery query;
query.Table = GetType()->GetTable() + "_timeranges";
@ -111,8 +106,8 @@ void TimePeriodDbObject::OnConfigUpdate(void)
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", mktime(&begin));
query.Fields->Set("end_sec", mktime(&end));
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);
}
}