mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
parent
c65c899926
commit
62bde62961
1 changed files with 14 additions and 40 deletions
|
@ -40,6 +40,7 @@ int CmdLengthen (
|
||||||
Journal& journal)
|
Journal& journal)
|
||||||
{
|
{
|
||||||
// Gather IDs and TAGs.
|
// Gather IDs and TAGs.
|
||||||
|
const bool verbose = rules.getBoolean ("verbose");
|
||||||
std::set <int> ids = cli.getIds ();
|
std::set <int> ids = cli.getIds ();
|
||||||
|
|
||||||
if (ids.empty ())
|
if (ids.empty ())
|
||||||
|
@ -56,53 +57,26 @@ int CmdLengthen (
|
||||||
|
|
||||||
journal.startTransaction ();
|
journal.startTransaction ();
|
||||||
|
|
||||||
// Load the data.
|
flattenDatabase (database, rules);
|
||||||
// Note: There is no filter.
|
std::vector <Interval> intervals = getIntervalsByIds (database, rules, ids);
|
||||||
Interval filter;
|
|
||||||
auto tracked = getTracked (database, rules, filter);
|
|
||||||
|
|
||||||
bool dirty = true;
|
|
||||||
|
|
||||||
for (auto& id : ids)
|
|
||||||
{
|
|
||||||
if (id > static_cast <int> (tracked.size ()))
|
|
||||||
throw format ("ID '@{1}' does not correspond to any tracking.", id);
|
|
||||||
|
|
||||||
if (tracked[tracked.size () - id].synthetic && dirty)
|
|
||||||
{
|
|
||||||
auto latest = getLatestInterval (database);
|
|
||||||
auto exclusions = getAllExclusions (rules, filter);
|
|
||||||
|
|
||||||
Interval modified {latest};
|
|
||||||
|
|
||||||
// Update database.
|
|
||||||
database.deleteInterval (latest);
|
|
||||||
for (auto& interval : flatten (modified, exclusions))
|
|
||||||
database.addInterval (interval, rules.getBoolean ("verbose"));
|
|
||||||
|
|
||||||
dirty = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lengthen intervals specified by ids
|
// Lengthen intervals specified by ids
|
||||||
for (auto& id : ids)
|
for (auto& interval : intervals)
|
||||||
{
|
{
|
||||||
if (id > static_cast <int> (tracked.size ()))
|
if (interval.is_open ())
|
||||||
throw format ("ID '@{1}' does not correspond to any tracking.", id);
|
throw format ("Cannot lengthen open interval @{1}", interval.id);
|
||||||
|
|
||||||
Interval i = tracked[tracked.size () - id];
|
database.deleteInterval (interval);
|
||||||
if (i.is_open ())
|
|
||||||
throw format ("Cannot lengthen open interval @{1}", id);
|
|
||||||
|
|
||||||
database.deleteInterval (tracked[tracked.size () - id]);
|
|
||||||
|
|
||||||
Duration dur (delta);
|
Duration dur (delta);
|
||||||
i.end += dur.toTime_t ();
|
interval.end += dur.toTime_t ();
|
||||||
validate (cli, rules, database, i);
|
validate (cli, rules, database, interval);
|
||||||
database.addInterval (i, rules.getBoolean ("verbose"));
|
database.addInterval (interval, verbose);
|
||||||
|
|
||||||
if (rules.getBoolean ("verbose"))
|
if (verbose)
|
||||||
std::cout << "Lengthened @" << id << " by " << dur.formatHours () << '\n';
|
{
|
||||||
|
std::cout << "Lengthened @" << interval.id << " by " << dur.formatHours () << '\n';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
journal.endTransaction ();
|
journal.endTransaction ();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue