From ee2960b9b09ec2db9d54390812291651cf0e229e Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 16 Aug 2011 23:50:26 -0400 Subject: [PATCH] Date/Duration Distinction - When a date attribute is updated, the expression may have evaluated to a duration, which at this point is simply a number. If it is below a certain threshold (5y) then it is considered a duration and added to 'now', otherwise it is considered a date. --- src/commands/Command.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index 279204901..5908eee99 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -420,6 +420,9 @@ void Command::modify_task ( { std::cout << "# Command::modify_task name='" << name << "' value='" << value << "'\n"; + // Get the column info. + Column* column = context.columns[name]; + // All values must be eval'd first. A3 fragment; fragment.capture (value); @@ -447,6 +450,22 @@ void Command::modify_task ( } } + // Dates are special, maybe. + else if (column->type () == "date") + { + // If the date value is less than 5 years, it is a duration, not a + // date, therefore add 'now'. + long l = strtol (result.c_str (), NULL, 10); + if (labs (l) < 5 * 365 * 86400) + { + Date now; + now += l; + task.set (name, now.toEpochString ()); + } + else + task.set (name, result); + } + // By default, just add it. else task.set (name, result);