mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-06-26 10:54:28 +02:00
Replace getLatestInterval by new interval filtering
Replace in commands CmdAnnotate, CmdDefault, CmdContinue, CmdTag, and CmdUntag Also in function domGet Relates to #468 Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
This commit is contained in:
parent
9cd693d55d
commit
40d0c656e7
6 changed files with 48 additions and 30 deletions
|
@ -31,6 +31,8 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <IntervalFilterAllWithIds.h>
|
#include <IntervalFilterAllWithIds.h>
|
||||||
|
#include <IntervalFilterAllInRange.h>
|
||||||
|
#include <IntervalFilterFirstOf.h>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int CmdAnnotate (
|
int CmdAnnotate (
|
||||||
|
@ -50,18 +52,17 @@ int CmdAnnotate (
|
||||||
|
|
||||||
if (ids.empty ())
|
if (ids.empty ())
|
||||||
{
|
{
|
||||||
auto latest = getLatestInterval (database);
|
auto filtering = IntervalFilterFirstOf (new IntervalFilterAllInRange ({0, 0}));
|
||||||
|
intervals = getTracked (database, rules, filtering);
|
||||||
|
|
||||||
if (latest.empty ())
|
if (intervals.empty ())
|
||||||
{
|
{
|
||||||
throw std::string ("There is no active time tracking.");
|
throw std::string ("There is no active time tracking.");
|
||||||
}
|
}
|
||||||
else if (!latest.is_open ())
|
else if (!intervals.at (0).is_open ())
|
||||||
{
|
{
|
||||||
throw std::string ("At least one ID must be specified. See 'timew help annotate'.");
|
throw std::string ("At least one ID must be specified. See 'timew help annotate'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
intervals.push_back (latest);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include <IntervalFilterAllWithIds.h>
|
#include <IntervalFilterAllWithIds.h>
|
||||||
#include <IntervalFilterAllWithTags.h>
|
#include <IntervalFilterAllWithTags.h>
|
||||||
#include <IntervalFilterFirstOf.h>
|
#include <IntervalFilterFirstOf.h>
|
||||||
|
#include <IntervalFilterAllInRange.h>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int CmdContinue (
|
int CmdContinue (
|
||||||
|
@ -61,49 +62,47 @@ int CmdContinue (
|
||||||
throw std::string ("You can only specify one ID to continue.");
|
throw std::string ("You can only specify one ID to continue.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Interval to_copy;
|
std::vector <Interval> intervals;
|
||||||
|
|
||||||
if (ids.size () == 1)
|
if (ids.size () == 1)
|
||||||
{
|
{
|
||||||
auto filtering = IntervalFilterAllWithIds (ids);
|
auto filtering = IntervalFilterAllWithIds (ids);
|
||||||
auto intervals = getTracked (database, rules, filtering);
|
intervals = getTracked (database, rules, filtering);
|
||||||
|
|
||||||
if (intervals.empty ())
|
if (intervals.empty ())
|
||||||
{
|
{
|
||||||
throw format ("ID '@{1}' does not correspond to any tracking.", *ids.begin ());
|
throw format ("ID '@{1}' does not correspond to any tracking.", *ids.begin ());
|
||||||
}
|
}
|
||||||
|
|
||||||
assert (intervals.size () == 1);
|
|
||||||
to_copy = intervals.front ();
|
|
||||||
}
|
}
|
||||||
else if (!filter.tags ().empty ())
|
else if (!filter.tags ().empty ())
|
||||||
{
|
{
|
||||||
auto filtering = IntervalFilterFirstOf { new IntervalFilterAllWithTags (filter.tags ())};
|
auto filtering = IntervalFilterFirstOf { new IntervalFilterAllWithTags (filter.tags ())};
|
||||||
auto tracked = getTracked (database, rules, filtering);
|
intervals = getTracked (database, rules, filtering);
|
||||||
|
|
||||||
if (tracked.empty())
|
if (intervals.empty ())
|
||||||
{
|
{
|
||||||
throw format ("Tags '{1}' do not correspond to any tracking.", joinQuotedIfNeeded (", ", filter.tags ()));
|
throw format ("Tags '{1}' do not correspond to any tracking.", joinQuotedIfNeeded (", ", filter.tags ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
to_copy = tracked.back();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Interval latest = getLatestInterval (database);
|
auto filtering = IntervalFilterFirstOf (new IntervalFilterAllInRange ({0, 0}));
|
||||||
|
intervals = getTracked (database, rules, filtering);
|
||||||
|
|
||||||
if (latest.empty ())
|
if (intervals.empty ())
|
||||||
{
|
{
|
||||||
throw std::string ("There is no previous tracking to continue.");
|
throw std::string ("There is no previous tracking to continue.");
|
||||||
}
|
}
|
||||||
if (latest.is_open ())
|
|
||||||
|
if (intervals.at (0).is_open ())
|
||||||
{
|
{
|
||||||
throw std::string ("There is already active tracking.");
|
throw std::string ("There is already active tracking.");
|
||||||
}
|
}
|
||||||
|
|
||||||
to_copy = latest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert (intervals.size () == 1);
|
||||||
|
auto to_copy = intervals.back ();
|
||||||
|
|
||||||
Datetime start_time;
|
Datetime start_time;
|
||||||
Datetime end_time;
|
Datetime end_time;
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
#include <commands.h>
|
#include <commands.h>
|
||||||
#include <timew.h>
|
#include <timew.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <IntervalFilterAllInRange.h>
|
||||||
|
#include <IntervalFilterFirstOf.h>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Returns 0 if tracking is active, 1 if not.
|
// Returns 0 if tracking is active, 1 if not.
|
||||||
|
@ -35,13 +37,14 @@ int CmdDefault (Rules& rules, Database& database)
|
||||||
const bool verbose = rules.getBoolean ("verbose");
|
const bool verbose = rules.getBoolean ("verbose");
|
||||||
|
|
||||||
// Load the most recent interval, summarize and display.
|
// Load the most recent interval, summarize and display.
|
||||||
auto interval = getLatestInterval (database);
|
auto filtering = IntervalFilterFirstOf (new IntervalFilterAllInRange ({0, 0}));
|
||||||
|
auto latest = getTracked (database, rules, filtering);
|
||||||
|
|
||||||
if (interval.is_open ())
|
if (!latest.empty () && latest.at (0).is_open ())
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
std::cout << intervalSummarize (rules, interval);
|
std::cout << intervalSummarize (rules, latest.at (0));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <IntervalFilterAllWithIds.h>
|
#include <IntervalFilterAllWithIds.h>
|
||||||
|
#include <IntervalFilterAllInRange.h>
|
||||||
|
#include <IntervalFilterFirstOf.h>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int CmdTag (
|
int CmdTag (
|
||||||
|
@ -58,18 +60,19 @@ int CmdTag (
|
||||||
|
|
||||||
if (ids.empty ())
|
if (ids.empty ())
|
||||||
{
|
{
|
||||||
auto latest = getLatestInterval (database);
|
auto filtering = IntervalFilterFirstOf (new IntervalFilterAllInRange ({0, 0}));
|
||||||
|
auto latest = getTracked (database, rules, filtering);
|
||||||
|
|
||||||
if (latest.empty ())
|
if (latest.empty ())
|
||||||
{
|
{
|
||||||
throw std::string ("There is no active time tracking.");
|
throw std::string ("There is no active time tracking.");
|
||||||
}
|
}
|
||||||
else if (!latest.is_open ())
|
else if (!latest.at (0).is_open ())
|
||||||
{
|
{
|
||||||
throw std::string ("At least one ID must be specified. See 'timew help tag'.");
|
throw std::string ("At least one ID must be specified. See 'timew help tag'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
intervals.push_back (latest);
|
intervals = latest;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,6 +31,8 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <IntervalFilterAllWithIds.h>
|
#include <IntervalFilterAllWithIds.h>
|
||||||
|
#include <IntervalFilterAllInRange.h>
|
||||||
|
#include <IntervalFilterFirstOf.h>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int CmdUntag (
|
int CmdUntag (
|
||||||
|
@ -57,18 +59,19 @@ int CmdUntag (
|
||||||
|
|
||||||
if (ids.empty ())
|
if (ids.empty ())
|
||||||
{
|
{
|
||||||
auto latest = getLatestInterval (database);
|
auto filtering = IntervalFilterFirstOf (new IntervalFilterAllInRange ({0, 0}));
|
||||||
|
auto latest = getTracked (database, rules, filtering);
|
||||||
|
|
||||||
if (latest.empty ())
|
if (latest.empty ())
|
||||||
{
|
{
|
||||||
throw std::string ("There is no active time tracking.");
|
throw std::string ("There is no active time tracking.");
|
||||||
}
|
}
|
||||||
else if (!latest.is_open ())
|
else if (!latest.at (0).is_open ())
|
||||||
{
|
{
|
||||||
throw std::string ("At least one ID must be specified. See 'timew help untag'.");
|
throw std::string ("At least one ID must be specified. See 'timew help untag'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
intervals.push_back (latest);
|
intervals = latest;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
13
src/dom.cpp
13
src/dom.cpp
|
@ -34,6 +34,7 @@
|
||||||
#include <IntervalFilterAllInRange.h>
|
#include <IntervalFilterAllInRange.h>
|
||||||
#include <IntervalFilterAllWithTags.h>
|
#include <IntervalFilterAllWithTags.h>
|
||||||
#include <IntervalFilterAndGroup.h>
|
#include <IntervalFilterAndGroup.h>
|
||||||
|
#include "IntervalFilterFirstOf.h"
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool domGet (
|
bool domGet (
|
||||||
|
@ -49,15 +50,23 @@ bool domGet (
|
||||||
// dom.active
|
// dom.active
|
||||||
if (pig.skipLiteral ("active"))
|
if (pig.skipLiteral ("active"))
|
||||||
{
|
{
|
||||||
auto latest = getLatestInterval (database);
|
auto filtering = IntervalFilterFirstOf (new IntervalFilterAllInRange ({0, 0}));
|
||||||
|
auto intervals = getTracked (database, rules, filtering);
|
||||||
|
|
||||||
// dom.active
|
// dom.active
|
||||||
if (pig.eos ())
|
if (pig.eos ())
|
||||||
{
|
{
|
||||||
value = latest.is_open () ? "1" : "0";
|
value = !intervals.empty () && intervals.at (0).is_open () ? "1" : "0";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (intervals.empty ())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto latest = intervals.at (0);
|
||||||
|
|
||||||
// dom.active.start
|
// dom.active.start
|
||||||
if (pig.skipLiteral (".start") &&
|
if (pig.skipLiteral (".start") &&
|
||||||
latest.is_open ())
|
latest.is_open ())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue