CmdStop: Fixed bug where tags were removed too soon, and for the wrong reason

This commit is contained in:
Paul Beckingham 2016-06-18 12:11:37 -04:00
parent f1d6440926
commit 537ed367dc

View file

@ -32,6 +32,17 @@
#include <Lexer.h> #include <Lexer.h>
#include <iostream> #include <iostream>
template <class T> T setIntersect (
const T& left, const T& right)
{
T intersection;
for (auto& l : left)
if (std::find (right.begin (), right.end (), l) != right.end ())
intersection.insert (l);
return intersection;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdStop ( int CmdStop (
const CLI& cli, const CLI& cli,
@ -54,21 +65,28 @@ int CmdStop (
else else
modified.range.end = Datetime (); modified.range.end = Datetime ();
// Remove the filter tags. // Close the interval.
database.modifyInterval (latest, modified);
// If tags are specified, but are not a full set of tags, remove them
// before closing the interval.
if (filter.tags ().size () &&
(setIntersect (filter.tags (), latest.tags ()).size () != latest.tags ().size ()))
{
for (auto& tag : filter.tags ()) for (auto& tag : filter.tags ())
if (modified.hasTag (tag)) if (modified.hasTag (tag))
modified.untag (tag); modified.untag (tag);
else else
throw format ("The current interval does not have the '{1}' tag.", tag); throw format ("The current interval does not have the '{1}' tag.", tag);
}
// Close the interval.
database.modifyInterval (latest, modified);
latest.range.end = modified.range.end; latest.range.end = modified.range.end;
if (rules.getBoolean ("verbose")) if (rules.getBoolean ("verbose"))
std::cout << intervalSummarize (database, rules, latest); std::cout << intervalSummarize (database, rules, latest);
// Open a new interval with remaining tags, if any. // Open a new interval with remaining tags, if any.
if (filter.tags ().size () && modified.tags ().size ()) if (filter.tags ().size () &&
modified.tags ().size () != latest.tags ().size ())
{ {
modified.range.start = modified.range.end; modified.range.start = modified.range.end;
modified.range.end = {0}; modified.range.end = {0};