From 82b5c27fe854e4e2e6cbf680b2c480bc81e37df3 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 31 Jan 2016 20:06:30 -0500 Subject: [PATCH] ColTypeDate: Migrated part of Task::modify to ::modify --- src/columns/ColTypeDate.cpp | 43 ++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/columns/ColTypeDate.cpp b/src/columns/ColTypeDate.cpp index 3e58cb48d..c46f87eca 100644 --- a/src/columns/ColTypeDate.cpp +++ b/src/columns/ColTypeDate.cpp @@ -28,10 +28,15 @@ #include #include #include +#include +#include +#include +#include #include #include extern Context context; +extern Task& contextTask; //////////////////////////////////////////////////////////////////////////////// ColumnTypeDate::ColumnTypeDate () @@ -203,7 +208,43 @@ void ColumnTypeDate::render ( //////////////////////////////////////////////////////////////////////////////// void ColumnTypeDate::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); + } + + // If v is duration, add 'now' to it, else store as date. + std::string label = " MODIFICATION "; + if (evaluatedValue.type () == Variant::type_duration) + { + context.debug (label + _name + " <-- '" + format ("{1}", format (evaluatedValue.get_duration ())) + "' <-- '" + (std::string) evaluatedValue + "' <-- '" + value + "'"); + Variant now; + if (namedDates ("now", now)) + evaluatedValue += now; + } + else + { + evaluatedValue.cast (Variant::type_date); + context.debug (label + _name + " <-- '" + format ("{1}", evaluatedValue.get_date ()) + "' <-- '" + (std::string) evaluatedValue + "' <-- '" + value + "'"); + } + + // If a date doesn't parse (2/29/2014) then it evaluates to zero. + if (value != "" && + evaluatedValue.get_date () == 0) + throw format (STRING_DATE_INVALID_FORMAT, value, Variant::dateFormat); + + task.set (_name, evaluatedValue.get_date ()); } ////////////////////////////////////////////////////////////////////////////////