From aa6b5dbfba94141515f552f8286592b9b969c1a6 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 10 Apr 2017 19:08:07 -0400 Subject: [PATCH] Recurrence: Added stubbed generateAllDueDates --- src/recur2.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/src/recur2.cpp b/src/recur2.cpp index 4feeea53f..49c110d61 100644 --- a/src/recur2.cpp +++ b/src/recur2.cpp @@ -263,7 +263,62 @@ static Datetime generateNextDueDate ( } //////////////////////////////////////////////////////////////////////////////// -static void synthesizeTasks (const Task&) +// Calculates the due date for a new instance N. +static std::vector generateAllDueDates (const Task& templateTask) +{ + std::vector 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");