mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Optimize handling of implicit latest interval
- If no id is given but active time tracking (i.e. open interval) is present then apply the command to the open interval
This commit is contained in:
parent
711848915b
commit
35a38d628c
4 changed files with 36 additions and 31 deletions
|
@ -43,28 +43,30 @@ int CmdAnnotate (
|
|||
std::string annotation = cli.getAnnotation ();
|
||||
|
||||
journal.startTransaction ();
|
||||
|
||||
flattenDatabase (database, rules);
|
||||
auto intervals = getIntervalsByIds (database, rules, ids);
|
||||
std::vector <Interval> intervals;
|
||||
|
||||
if (ids.empty ())
|
||||
{
|
||||
if (database.empty ())
|
||||
auto latest = getLatestInterval (database);
|
||||
|
||||
if (latest.empty ())
|
||||
{
|
||||
throw std::string ("There is no active time tracking.");
|
||||
}
|
||||
|
||||
auto latest = getLatestInterval (database);
|
||||
if (!latest.is_open ())
|
||||
else if (!latest.is_open ())
|
||||
{
|
||||
throw std::string ("At least one ID must be specified. See 'timew help annotate'.");
|
||||
}
|
||||
|
||||
latest.id = 1;
|
||||
intervals.push_back (latest);
|
||||
}
|
||||
else
|
||||
{
|
||||
intervals = getIntervalsByIds (database, rules, ids);
|
||||
}
|
||||
|
||||
// Apply annotations to ids.
|
||||
// Apply annotations to intervals.
|
||||
for (const auto& interval : intervals)
|
||||
{
|
||||
Interval modified {interval};
|
||||
|
|
|
@ -52,27 +52,29 @@ int CmdTag (
|
|||
journal.startTransaction ();
|
||||
|
||||
flattenDatabase (database, rules);
|
||||
auto intervals = getIntervalsByIds (database, rules, ids);
|
||||
std::vector <Interval> intervals;
|
||||
|
||||
if (intervals.empty ())
|
||||
if (ids.empty ())
|
||||
{
|
||||
if (database.empty ())
|
||||
auto latest = getLatestInterval (database);
|
||||
|
||||
if (latest.empty ())
|
||||
{
|
||||
throw std::string ("There is no active time tracking.");
|
||||
}
|
||||
|
||||
auto latest = getLatestInterval (database);
|
||||
|
||||
if (!latest.is_open ())
|
||||
else if (!latest.is_open ())
|
||||
{
|
||||
throw std::string ("At least one ID must be specified. See 'timew help tag'.");
|
||||
}
|
||||
|
||||
latest.id = 1;
|
||||
intervals.push_back (latest);
|
||||
}
|
||||
else
|
||||
{
|
||||
intervals = getIntervalsByIds (database, rules, ids);
|
||||
}
|
||||
|
||||
// Apply tags to ids.
|
||||
// Apply tags to intervals.
|
||||
for (const auto& interval : intervals)
|
||||
{
|
||||
Interval modified {interval};
|
||||
|
@ -82,7 +84,6 @@ int CmdTag (
|
|||
modified.tag (tag);
|
||||
}
|
||||
|
||||
//TODO validate (cli, rules, database, i);
|
||||
database.modifyInterval (interval, modified, verbose);
|
||||
|
||||
if (verbose)
|
||||
|
|
|
@ -51,27 +51,29 @@ int CmdUntag (
|
|||
journal.startTransaction ();
|
||||
|
||||
flattenDatabase (database, rules);
|
||||
auto intervals = getIntervalsByIds (database, rules, ids);
|
||||
std::vector <Interval> intervals;
|
||||
|
||||
if (intervals.empty ())
|
||||
if (ids.empty ())
|
||||
{
|
||||
if (database.empty ())
|
||||
auto latest = getLatestInterval (database);
|
||||
|
||||
if (latest.empty ())
|
||||
{
|
||||
throw std::string ("There is no active time tracking.");
|
||||
}
|
||||
|
||||
auto latest = getLatestInterval (database);
|
||||
|
||||
if (!latest.is_open ())
|
||||
else if (!latest.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 untag'.");
|
||||
}
|
||||
|
||||
latest.id = 1;
|
||||
intervals.push_back (latest);
|
||||
}
|
||||
else
|
||||
{
|
||||
intervals = getIntervalsByIds (database, rules, ids);
|
||||
}
|
||||
|
||||
// Remove tags from ids.
|
||||
// Remove tags from intervals.
|
||||
for (const auto& interval : intervals)
|
||||
{
|
||||
Interval modified {interval};
|
||||
|
@ -81,7 +83,6 @@ int CmdUntag (
|
|||
modified.untag (tag);
|
||||
}
|
||||
|
||||
//TODO validate (cli, rules, database, i);
|
||||
database.modifyInterval (interval, modified, verbose);
|
||||
|
||||
if (verbose)
|
||||
|
|
|
@ -675,7 +675,7 @@ std::vector <Interval> getTracked (
|
|||
{
|
||||
auto begin = database.rbegin ();
|
||||
auto end = database.rend ();
|
||||
if (begin != end)
|
||||
if (begin != end)
|
||||
{
|
||||
filter.start = IntervalFactory::fromSerialization (*begin).start;
|
||||
}
|
||||
|
@ -703,7 +703,7 @@ std::vector <Interval> getTracked (
|
|||
else if (interval.start.toEpoch () >= filter.start.toEpoch ())
|
||||
{
|
||||
++id_skip;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
|
@ -788,6 +788,7 @@ Interval getLatestInterval (Database& database)
|
|||
if (! latestEntry.empty ())
|
||||
{
|
||||
i = IntervalFactory::fromSerialization (latestEntry);
|
||||
i.id = 1;
|
||||
}
|
||||
|
||||
return i;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue