From 87dcbd556ecb5d2e439d6b71267629388050561f Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 30 May 2014 21:29:42 -0400 Subject: [PATCH] Recurrence - Task::validate and getNextRecurrence needed to consider both Duration and ISO8601p. --- src/Task.cpp | 14 +++++++++++--- src/recur.cpp | 19 +++++++++++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/Task.cpp b/src/Task.cpp index a0662d198..134d8cf99 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -55,6 +55,7 @@ #include #include #include +#include #define APPROACHING_INFINITY 1000 // Close enough. This isn't rocket surgery. @@ -1574,10 +1575,17 @@ void Task::validate (bool applyDefault /* = true */) // Recur durations must be valid. if (has ("recur")) { - Duration d; + std::string value = get ("recur"); + + ISO8601p p; std::string::size_type i = 0; - if (! d.parse (get ("recur"), i)) - throw std::string (format (STRING_TASK_VALID_RECUR, get ("recur"))); + if (! p.parse (value, i)) + { + i = 0; + Duration d; + if (! d.parse (value, i)) + throw std::string (format (STRING_TASK_VALID_RECUR, value)); + } } // Priorities must be valid. diff --git a/src/recur.cpp b/src/recur.cpp index 4728d1010..e1b536850 100644 --- a/src/recur.cpp +++ b/src/recur.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -336,10 +337,24 @@ Date getNextRecurrence (Date& current, std::string& period) // If the period is an 'easy' one, add it to current, and we're done. // If it throws an error, the duration was not recognized. + int secs = 0; std::string::size_type idx = 0; Duration du; - du.parse (period, idx); - int secs = du; + if (du.parse (period, idx)) + { + secs = du; + } + else + { + idx = 0; + ISO8601p p; + if (p.parse (period, idx)) + { + secs = p; + } + else + throw std::string (format (STRING_TASK_VALID_RECUR, period)); + } return current + secs; }