#include <sstream>
#include <app.h>
#include <contacts.h>
+#include <functional>
SINGLETON_INSTANCE(CalDataManager);
}
originalSchedule->truncateRepeatToBeforeDate(inputInstanceStartTime);
+ __deleteChildRecords(*originalSchedule, inputInstanceStartTime, false);
__updateSchedule(*originalSchedule);
__deleteExceptionRecordsOnAndAfter(*originalSchedule, inputInstanceStartTime);
}
originalSchedule->truncateRepeatToBeforeDate(inputInstanceStartTime);
+ __deleteChildRecords(*originalSchedule, inputInstanceStartTime, false);
__updateSchedule(*originalSchedule);
__deleteExceptionRecordsOnAndAfter(*originalSchedule, inputInstanceStartTime);
}
const auto originalSchedule = __getOriginalSchedule(inputSchedule);
int countBefore = originalSchedule->getInstanceCountBeforeDate(inputInstanceStartTime);
- __deleteChildRecordsBefore(workingCopy, inputInstanceStartTime);
+ __deleteChildRecords(workingCopy, inputInstanceStartTime);
repeat.untilInfo.times -= countBefore;
repeat.print();
}
}
-void CalDataManager::__deleteChildRecordsBefore(const CalOriginalSchedule& originalSchedule, const CalDateTime& inputInstanceStartTime)
+void CalDataManager::__deleteChildRecords(const CalSchedule& originalSchedule, const CalDateTime& inputInstanceStartTime, bool before)
{
+ typedef long long int OperandType;
+ typedef std::function<bool(const OperandType &, const OperandType &)> Comparator;
+
+ Comparator comparator;
+ if (before) {
+ comparator = std::less<OperandType>();
+ } else {
+ comparator = std::greater_equal<OperandType>();
+ }
calendar_record_h origRecord = originalSchedule.getRecord();
+
if (origRecord) {
unsigned count = 0;
calendar_record_get_child_record_count(origRecord, _calendar_event.exception, &count);
calendar_time_s calTime = { CALENDAR_TIME_UTIME, { 0, } };
calendar_record_get_caltime(childRecord, _calendar_event.start_time, &calTime);
- if (calTime.time.utime < inputInstanceStartTime.getUtimeFromTm()) {
+
+ if (comparator(calTime.time.utime, inputInstanceStartTime.getUtimeFromTm())) {
calendar_record_remove_child_record(origRecord, _calendar_event.exception, childRecord);
}
}
static void __onChanged(const char* uri, void* userData);
static std::shared_ptr<CalOriginalSchedule> __getOriginalSchedule(const CalSchedule& instance);
static void __deleteExceptionRecordsOnAndAfter(const CalOriginalSchedule& originalSchedule, const CalDateTime& inputInstanceStartTime);
- static void __deleteChildRecordsBefore(const CalOriginalSchedule& originalSchedule, const CalDateTime& inputInstanceStartTime);
+ static void __deleteChildRecords(const CalSchedule& originalSchedule, const CalDateTime& inputInstanceStartTime, bool before = true);
static void __deleteAllExceptionRecords(const CalOriginalSchedule& originalSchedule);
int __localVersion;