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 <stdlib.h>
|
||||
#include <IntervalFilterAllWithIds.h>
|
||||
#include <IntervalFilterAllInRange.h>
|
||||
#include <IntervalFilterFirstOf.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int CmdAnnotate (
|
||||
|
@ -50,18 +52,17 @@ int CmdAnnotate (
|
|||
|
||||
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.");
|
||||
}
|
||||
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'.");
|
||||
}
|
||||
|
||||
intervals.push_back (latest);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <IntervalFilterAllWithIds.h>
|
||||
#include <IntervalFilterAllWithTags.h>
|
||||
#include <IntervalFilterFirstOf.h>
|
||||
#include <IntervalFilterAllInRange.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int CmdContinue (
|
||||
|
@ -61,49 +62,47 @@ int CmdContinue (
|
|||
throw std::string ("You can only specify one ID to continue.");
|
||||
}
|
||||
|
||||
Interval to_copy;
|
||||
std::vector <Interval> intervals;
|
||||
|
||||
if (ids.size () == 1)
|
||||
{
|
||||
auto filtering = IntervalFilterAllWithIds (ids);
|
||||
auto intervals = getTracked (database, rules, filtering);
|
||||
intervals = getTracked (database, rules, filtering);
|
||||
|
||||
if (intervals.empty ())
|
||||
{
|
||||
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 ())
|
||||
{
|
||||
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 ()));
|
||||
}
|
||||
|
||||
to_copy = tracked.back();
|
||||
}
|
||||
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.");
|
||||
}
|
||||
if (latest.is_open ())
|
||||
|
||||
if (intervals.at (0).is_open ())
|
||||
{
|
||||
throw std::string ("There is already active tracking.");
|
||||
}
|
||||
|
||||
to_copy = latest;
|
||||
}
|
||||
|
||||
assert (intervals.size () == 1);
|
||||
auto to_copy = intervals.back ();
|
||||
|
||||
Datetime start_time;
|
||||
Datetime end_time;
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#include <commands.h>
|
||||
#include <timew.h>
|
||||
#include <iostream>
|
||||
#include <IntervalFilterAllInRange.h>
|
||||
#include <IntervalFilterFirstOf.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// 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");
|
||||
|
||||
// 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)
|
||||
{
|
||||
std::cout << intervalSummarize (rules, interval);
|
||||
std::cout << intervalSummarize (rules, latest.at (0));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
#include <IntervalFilterAllWithIds.h>
|
||||
#include <IntervalFilterAllInRange.h>
|
||||
#include <IntervalFilterFirstOf.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int CmdTag (
|
||||
|
@ -58,18 +60,19 @@ int CmdTag (
|
|||
|
||||
if (ids.empty ())
|
||||
{
|
||||
auto latest = getLatestInterval (database);
|
||||
auto filtering = IntervalFilterFirstOf (new IntervalFilterAllInRange ({0, 0}));
|
||||
auto latest = getTracked (database, rules, filtering);
|
||||
|
||||
if (latest.empty ())
|
||||
{
|
||||
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'.");
|
||||
}
|
||||
|
||||
intervals.push_back (latest);
|
||||
intervals = latest;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
#include <IntervalFilterAllWithIds.h>
|
||||
#include <IntervalFilterAllInRange.h>
|
||||
#include <IntervalFilterFirstOf.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int CmdUntag (
|
||||
|
@ -57,18 +59,19 @@ int CmdUntag (
|
|||
|
||||
if (ids.empty ())
|
||||
{
|
||||
auto latest = getLatestInterval (database);
|
||||
auto filtering = IntervalFilterFirstOf (new IntervalFilterAllInRange ({0, 0}));
|
||||
auto latest = getTracked (database, rules, filtering);
|
||||
|
||||
if (latest.empty ())
|
||||
{
|
||||
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'.");
|
||||
}
|
||||
|
||||
intervals.push_back (latest);
|
||||
intervals = latest;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
13
src/dom.cpp
13
src/dom.cpp
|
@ -34,6 +34,7 @@
|
|||
#include <IntervalFilterAllInRange.h>
|
||||
#include <IntervalFilterAllWithTags.h>
|
||||
#include <IntervalFilterAndGroup.h>
|
||||
#include "IntervalFilterFirstOf.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool domGet (
|
||||
|
@ -49,15 +50,23 @@ bool domGet (
|
|||
// dom.active
|
||||
if (pig.skipLiteral ("active"))
|
||||
{
|
||||
auto latest = getLatestInterval (database);
|
||||
auto filtering = IntervalFilterFirstOf (new IntervalFilterAllInRange ({0, 0}));
|
||||
auto intervals = getTracked (database, rules, filtering);
|
||||
|
||||
// dom.active
|
||||
if (pig.eos ())
|
||||
{
|
||||
value = latest.is_open () ? "1" : "0";
|
||||
value = !intervals.empty () && intervals.at (0).is_open () ? "1" : "0";
|
||||
return true;
|
||||
}
|
||||
|
||||
if (intervals.empty ())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto latest = intervals.at (0);
|
||||
|
||||
// dom.active.start
|
||||
if (pig.skipLiteral (".start") &&
|
||||
latest.is_open ())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue