Recurrence
- Task::validate and getNextRecurrence needed to consider both Duration and ISO8601p.
This commit is contained in:
14
src/Task.cpp
14
src/Task.cpp
@@ -55,6 +55,7 @@
|
|||||||
#include <Variant.h>
|
#include <Variant.h>
|
||||||
#include <Filter.h>
|
#include <Filter.h>
|
||||||
#include <Dates.h>
|
#include <Dates.h>
|
||||||
|
#include <ISO8601.h>
|
||||||
|
|
||||||
#define APPROACHING_INFINITY 1000 // Close enough. This isn't rocket surgery.
|
#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.
|
// Recur durations must be valid.
|
||||||
if (has ("recur"))
|
if (has ("recur"))
|
||||||
{
|
{
|
||||||
Duration d;
|
std::string value = get ("recur");
|
||||||
|
|
||||||
|
ISO8601p p;
|
||||||
std::string::size_type i = 0;
|
std::string::size_type i = 0;
|
||||||
if (! d.parse (get ("recur"), i))
|
if (! p.parse (value, i))
|
||||||
throw std::string (format (STRING_TASK_VALID_RECUR, get ("recur")));
|
{
|
||||||
|
i = 0;
|
||||||
|
Duration d;
|
||||||
|
if (! d.parse (value, i))
|
||||||
|
throw std::string (format (STRING_TASK_VALID_RECUR, value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Priorities must be valid.
|
// Priorities must be valid.
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
#include <Date.h>
|
#include <Date.h>
|
||||||
#include <Duration.h>
|
#include <Duration.h>
|
||||||
|
#include <ISO8601.h>
|
||||||
#include <text.h>
|
#include <text.h>
|
||||||
#include <util.h>
|
#include <util.h>
|
||||||
#include <i18n.h>
|
#include <i18n.h>
|
||||||
@@ -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 the period is an 'easy' one, add it to current, and we're done.
|
||||||
// If it throws an error, the duration was not recognized.
|
// If it throws an error, the duration was not recognized.
|
||||||
|
int secs = 0;
|
||||||
std::string::size_type idx = 0;
|
std::string::size_type idx = 0;
|
||||||
Duration du;
|
Duration du;
|
||||||
du.parse (period, idx);
|
if (du.parse (period, idx))
|
||||||
int secs = du;
|
{
|
||||||
|
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;
|
return current + secs;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user