From b7a72c52529856c8c148276685de71f04cd47da3 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 31 Jan 2016 20:08:32 -0500 Subject: [PATCH] ColTypeDuration: Migrated part of Task::modify to ::modify --- src/columns/ColTypeDuration.cpp | 38 ++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/columns/ColTypeDuration.cpp b/src/columns/ColTypeDuration.cpp index 049b0327e..c4f5d54f0 100644 --- a/src/columns/ColTypeDuration.cpp +++ b/src/columns/ColTypeDuration.cpp @@ -26,6 +26,16 @@ #include #include +#include +#include +#include +#include +#include +#include +#include + +extern Context context; +extern Task& contextTask; //////////////////////////////////////////////////////////////////////////////// ColumnTypeDuration::ColumnTypeDuration () @@ -51,7 +61,33 @@ void ColumnTypeDuration::render ( //////////////////////////////////////////////////////////////////////////////// void ColumnTypeDuration::modify (Task& task, const std::string& value) { - task.set (_name, value); + // Try to evaluate 'value'. It might work. + Variant evaluatedValue; + try + { + Eval e; + e.addSource (domSource); + e.addSource (namedDates); + contextTask = task; + e.evaluateInfixExpression (value, evaluatedValue); + } + + catch (...) + { + evaluatedValue = Variant (value); + } + + // The duration is stored in raw form, but it must still be valid, + // and therefore is parsed first. + std::string label = " MODIFICATION "; + if (evaluatedValue.type () == Variant::type_duration) + { + // Store the raw value, for 'recur'. + context.debug (label + _name + " <-- " + (std::string) evaluatedValue + " <-- '" + value + "'"); + task.set (_name, evaluatedValue); + } + else + throw format (STRING_TASK_INVALID_DUR, value); } ////////////////////////////////////////////////////////////////////////////////