Recurrence: Added stubbed generateAllDueDates

This commit is contained in:
Paul Beckingham 2017-04-10 19:08:07 -04:00
parent e62b395534
commit aa6b5dbfba

View file

@ -263,7 +263,62 @@ static Datetime generateNextDueDate (
}
////////////////////////////////////////////////////////////////////////////////
static void synthesizeTasks (const Task&)
// Calculates the due date for a new instance N.
static std::vector <Datetime> generateAllDueDates (const Task& templateTask)
{
std::vector <Datetime> dueDates;
// Determine due date, recur period and until date.
Datetime due (templateTask.get_date ("due"));
context.debug (" due " + due.toISOLocalExtended ());
auto recur = templateTask.get ("recur");
context.debug (" recur " + recur);
auto lastN = std::max (1, templateTask.get_int ("last"));
context.debug (format (" last {1}", lastN));
bool end_in_sight = false;
Datetime until;
if (templateTask.get ("until") != "")
{
until = Datetime (templateTask.get ("until"));
end_in_sight = true;
context.debug (" until " + until.toISOLocalExtended ());
}
auto recurrence_limit = context.config.getInteger ("recurrence.limit");
context.debug (format (" recurrence.limit {1}", recurrence_limit));
int recurrence_counter = 0;
Datetime now;
while (1)
{
Datetime nextDue = generateNextDueDate (due, recur, lastN);
// TODO Safety.
if (dueDates.size () && dueDates.back () == nextDue)
break;
// If nextDue > until, it means there are no more tasks to generate, so
// this templateTask is finished.
if (end_in_sight && nextDue > until)
break;
if (nextDue > now)
++recurrence_counter;
if (recurrence_counter >= recurrence_limit)
break;
dueDates.push_back (nextDue);
}
return dueDates;
}
////////////////////////////////////////////////////////////////////////////////
static void synthesizeTasks (const Task& templateTask)
{
context.debug ("synthesizeTasks start");