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)
|
||||
{
|
||||
// Gather IDs and TAGs.
|
||||
const bool verbose = rules.getBoolean ("verbose");
|
||||
std::set <int> ids = cli.getIds ();
|
||||
|
||||
if (ids.empty ())
|
||||
|
@ -56,53 +57,26 @@ int CmdLengthen (
|
|||
|
||||
journal.startTransaction ();
|
||||
|
||||
// Load the data.
|
||||
// Note: There is no filter.
|
||||
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;
|
||||
}
|
||||
}
|
||||
flattenDatabase (database, rules);
|
||||
std::vector <Interval> intervals = getIntervalsByIds (database, rules, ids);
|
||||
|
||||
// Lengthen intervals specified by ids
|
||||
for (auto& id : ids)
|
||||
for (auto& interval : intervals)
|
||||
{
|
||||
if (id > static_cast <int> (tracked.size ()))
|
||||
throw format ("ID '@{1}' does not correspond to any tracking.", id);
|
||||
if (interval.is_open ())
|
||||
throw format ("Cannot lengthen open interval @{1}", interval.id);
|
||||
|
||||
Interval i = tracked[tracked.size () - id];
|
||||
if (i.is_open ())
|
||||
throw format ("Cannot lengthen open interval @{1}", id);
|
||||
|
||||
database.deleteInterval (tracked[tracked.size () - id]);
|
||||
database.deleteInterval (interval);
|
||||
|
||||
Duration dur (delta);
|
||||
i.end += dur.toTime_t ();
|
||||
validate (cli, rules, database, i);
|
||||
database.addInterval (i, rules.getBoolean ("verbose"));
|
||||
interval.end += dur.toTime_t ();
|
||||
validate (cli, rules, database, interval);
|
||||
database.addInterval (interval, verbose);
|
||||
|
||||
if (rules.getBoolean ("verbose"))
|
||||
std::cout << "Lengthened @" << id << " by " << dur.formatHours () << '\n';
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "Lengthened @" << interval.id << " by " << dur.formatHours () << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
journal.endTransaction ();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue