From 6626207ad160aa2588979ac27f8bb736b7889b68 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 25 Jan 2015 14:49:02 -0500 Subject: [PATCH] TW-1522 - TW-1522 Date format doesn't like hyphens (thanks to Scott Carter). --- AUTHORS | 2 ++ ChangeLog | 1 + NEWS | 4 +++- doc/man/taskrc.5.in | 4 ++++ src/Config.cpp | 1 + src/Context.cpp | 1 + src/Lexer.cpp | 20 ++++++++++++-------- src/Lexer.h | 1 + src/Variant.cpp | 4 +++- src/Variant.h | 1 + src/commands/CmdShow.cpp | 1 + 11 files changed, 30 insertions(+), 10 deletions(-) diff --git a/AUTHORS b/AUTHORS index de5170283..c7500cd6e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -242,3 +242,5 @@ suggestions: Ozgur Akgun David Costa Sujeevan Vijayakumaran + Scott Carter + diff --git a/ChangeLog b/ChangeLog index 93c44df4f..c9d35b473 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,6 +20,7 @@ to Tomas Babej). - TW-1519 Testing suite forces taskd.trust="ignore hostname" (thanks to Renato Alves). +- TW-1522 Date format doesn't like hyphens (thanks to Scott Carter). - Fixed assorted color theme problems. - Changed assorted reports so they do not use '.age' format for dates that are in the future, because those are never shown with this format (thanks to diff --git a/NEWS b/NEWS index 1a7009979..8f6b80846 100644 --- a/NEWS +++ b/NEWS @@ -9,7 +9,9 @@ New commands in taskwarrior 2.4.1 New configuration options in taskwarrior 2.4.1 - - + - The 'date.iso' setting allows you to enable (default) or disable support + for ISO-8601 dates. This is because some of you have 'dateformat' settings + that conflict. Newly deprecated features in taskwarrior 2.4.1 diff --git a/doc/man/taskrc.5.in b/doc/man/taskrc.5.in index a43998ca0..d942a7577 100644 --- a/doc/man/taskrc.5.in +++ b/doc/man/taskrc.5.in @@ -615,6 +615,10 @@ field that is set. Otherwise, they are set to the corresponding values of .RE .RE +.TP +.B date.iso=yes +Enables ISO-8601 date support. The default value is "yes". + .TP .B weekstart=Sunday Determines the day a week starts. Valid values are Sunday or Monday only. The diff --git a/src/Config.cpp b/src/Config.cpp index a9eba1454..30cb95d86 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -116,6 +116,7 @@ std::string Config::_defaults = "dateformat.info=Y-M-D H:N:S # Preferred display date format for information\n" "dateformat.report= # Preferred display date format for reports\n" "dateformat.annotation= # Preferred display date format for annotations\n" + "date.iso=yes # Enable ISO date support\n" "weekstart=" STRING_DATE_SUNDAY_LONG " # Sunday or Monday only\n" diff --git a/src/Context.cpp b/src/Context.cpp index 7e70fb0c6..4d0e6bc0b 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -658,6 +658,7 @@ void Context::staticInitialization () Task::searchCaseSensitive = Variant::searchCaseSensitive = config.getBoolean ("search.case.sensitive"); Task::regex = Variant::searchUsingRegex = config.getBoolean ("regex"); Lexer::dateFormat = Variant::dateFormat = config.get ("dateformat"); + Lexer::isoEnabled = Variant::isoEnabled = config.getBoolean ("date.iso"); std::map ::iterator i; for (i = columns.begin (); i != columns.end (); ++i) diff --git a/src/Lexer.cpp b/src/Lexer.cpp index 05a15f7a7..371a3a4c8 100644 --- a/src/Lexer.cpp +++ b/src/Lexer.cpp @@ -34,6 +34,7 @@ #include std::string Lexer::dateFormat = ""; +bool Lexer::isoEnabled = true; //////////////////////////////////////////////////////////////////////////////// Lexer::Lexer (const std::string& input) @@ -732,15 +733,18 @@ void Lexer::dequote (std::string& input) bool Lexer::is_date (std::string& result) { // Try an ISO date parse. - std::string::size_type iso_i = 0; - std::string iso_result; - ISO8601d iso; - iso.ambiguity (_ambiguity); - if (iso.parse (_input.substr (_shift_counter), iso_i)) + if (isoEnabled) { - result = _input.substr (_shift_counter, iso_i); - while (iso_i--) shift (); - return true; + std::string::size_type iso_i = 0; + std::string iso_result; + ISO8601d iso; + iso.ambiguity (_ambiguity); + if (iso.parse (_input.substr (_shift_counter), iso_i)) + { + result = _input.substr (_shift_counter, iso_i); + while (iso_i--) shift (); + return true; + } } // Try a legacy rc.dateformat parse here. diff --git a/src/Lexer.h b/src/Lexer.h index 4b0e0fb92..b4a3bfa43 100644 --- a/src/Lexer.h +++ b/src/Lexer.h @@ -34,6 +34,7 @@ class Lexer { public: static std::string dateFormat; + static bool isoEnabled; enum Type { diff --git a/src/Variant.cpp b/src/Variant.cpp index 4e84daf18..d26aafe87 100644 --- a/src/Variant.cpp +++ b/src/Variant.cpp @@ -41,6 +41,7 @@ std::string Variant::dateFormat = ""; bool Variant::searchCaseSensitive = true; bool Variant::searchUsingRegex = true; +bool Variant::isoEnabled = true; //////////////////////////////////////////////////////////////////////////////// Variant::Variant () @@ -2065,7 +2066,8 @@ void Variant::cast (const enum type new_type) ISO8601d iso; std::string::size_type pos = 0; - if (iso.parse (_string, pos) && + if (isoEnabled && + iso.parse (_string, pos) && pos == _string.length ()) { _date = (time_t) iso; diff --git a/src/Variant.h b/src/Variant.h index d39646c91..6780acefa 100644 --- a/src/Variant.h +++ b/src/Variant.h @@ -37,6 +37,7 @@ public: static std::string dateFormat; static bool searchCaseSensitive; static bool searchUsingRegex; + static bool isoEnabled; enum type {type_unknown, type_boolean, type_integer, type_real, type_string, type_date, type_duration}; diff --git a/src/commands/CmdShow.cpp b/src/commands/CmdShow.cpp index 99b7fc71b..3a96b467f 100644 --- a/src/commands/CmdShow.cpp +++ b/src/commands/CmdShow.cpp @@ -134,6 +134,7 @@ int CmdShow::execute (std::string& output) " dateformat.holiday" " dateformat.info" " dateformat.report" + " date.iso" " debug" " debug.hooks" " debug.parser"