From 52eaf3f9c217a1b2140dbf1fc93a49d6abb0c64f Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Thu, 29 May 2014 00:43:39 -0400 Subject: [PATCH] Variant - Can now convert type_string to type_date via legacy dateformat, provided that Context transmits the format. --- NEWS | 5 +++-- src/Context.cpp | 3 +++ src/Variant.cpp | 9 +++++++++ src/Variant.h | 2 ++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index ead02d9a9..c5a487d8b 100644 --- a/NEWS +++ b/NEWS @@ -9,12 +9,13 @@ New Features in taskwarrior 2.4.0 TAGGED. - The '_get' command properly uses exit codes. - Regular expressions are now enabled by default. - - The 'filter' verbosity token shows the complete filter used for hte last + - The 'filter' verbosity token shows the complete filter used for the last command. New commands in taskwarrior 2.4.0 - - New 'calc' utility for quick command line calculations. + - New 'calc' command (and standalone utility) for quick command line + calculations. New configuration options in taskwarrior 2.4.0 diff --git a/src/Context.cpp b/src/Context.cpp index 99b72311d..1112b8705 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -639,6 +640,8 @@ void Context::staticInitialization () var->substr (0, 12) == "urgency.uda.") Task::coefficients[*var] = config.getReal (*var); } + + Variant::dateFormat = config.get ("dateformat"); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/Variant.cpp b/src/Variant.cpp index ee848a05d..514891f2a 100644 --- a/src/Variant.cpp +++ b/src/Variant.cpp @@ -31,10 +31,13 @@ #include #include #include +#include #include #include #include +std::string Variant::dateFormat = ""; + //////////////////////////////////////////////////////////////////////////////// Variant::Variant () : _type (type_unknown) @@ -1590,6 +1593,12 @@ void Variant::cast (const enum type new_type) { _date = (time_t) iso; } + // Support legacy date formats. + else if (dateFormat != "") + { + Date d (_string, dateFormat); + _date = d.toEpoch (); + } } break; case type_duration: diff --git a/src/Variant.h b/src/Variant.h index a4e24e14f..89734d62a 100644 --- a/src/Variant.h +++ b/src/Variant.h @@ -33,6 +33,8 @@ class Variant { public: + static std::string dateFormat; + enum type {type_unknown, type_boolean, type_integer, type_real, type_string, type_date, type_duration};