From c869ec16ed426820058d0c4b9da547c388d5ca23 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 13 Jun 2016 08:38:35 -0400 Subject: [PATCH] TI-7: Stop command shouldn't interrupt unrelated tags. - Tanks to Sergey Trofimov. --- ChangeLog | 2 ++ src/commands/CmdStop.cpp | 34 +++++++++++++++++----------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 04ab48a3..fadca3ab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,8 @@ (thanks to Sergey Trofimov). - TI-6 Exception after shortening task. (thanks to Sergey Trofimov). +- TI-7 Stop command shouldn't interrupt unrelated tags. + (thanks to Sergey Trofimov). - TI-8 Only the day's last interval is considered in the month report (thanks to Tomas Babej). - Added 'continue' command. diff --git a/src/commands/CmdStop.cpp b/src/commands/CmdStop.cpp index 5236ba5f..dc90e045 100644 --- a/src/commands/CmdStop.cpp +++ b/src/commands/CmdStop.cpp @@ -25,6 +25,7 @@ //////////////////////////////////////////////////////////////////////////////// #include +#include #include #include #include @@ -53,28 +54,27 @@ int CmdStop ( else modified.range.end = Datetime (); + // Remove the filter tags. + for (auto& tag : filter.tags ()) + if (modified.hasTag (tag)) + modified.untag (tag); + else + throw format ("The current interval does not have the '{1}' tag.", tag); + + // Close the interval. database.modifyInterval (latest, modified); - - // TODO intervalSummarїze needs to operate on a vector of similar intervals. + latest.range.end = modified.range.end; if (rules.getBoolean ("verbose")) - std::cout << intervalSummarize (database, rules, modified); + std::cout << intervalSummarize (database, rules, latest); - // If tags were specified, and after removing those tags, there are still - // tags remaining, then add a contiguous interval. - auto words = cli.getWords (); - if (words.size ()) - for (auto& word : cli.getWords ()) - latest.untag (Lexer::dequote (word)); - - if (words.size () && - latest.tags ().size ()) + // Open a new interval with remaining tags, if any. + if (filter.tags ().size () && modified.tags ().size ()) { - // Contiguous with previous interval. - latest.range.start = modified.range.end; - latest.range.end = Datetime (0); - database.addInterval (latest); + modified.range.start = modified.range.end; + modified.range.end = {0}; + database.addInterval (modified); if (rules.getBoolean ("verbose")) - std::cout << '\n' << intervalSummarize (database, rules, latest); + std::cout << '\n' << intervalSummarize (database, rules, modified); } } else