mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
CmdStop: Fixed bug where tags were removed too soon, and for the wrong reason
This commit is contained in:
parent
f1d6440926
commit
537ed367dc
1 changed files with 26 additions and 8 deletions
|
@ -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};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue