mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
CmdShorten: Cleanup
This commit is contained in:
parent
0ba4b40a6a
commit
beafe79b20
1 changed files with 19 additions and 31 deletions
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include <cmake.h>
|
||||
#include <Duration.h>
|
||||
#include <format.h>
|
||||
#include <commands.h>
|
||||
#include <timew.h>
|
||||
#include <iostream>
|
||||
|
@ -53,8 +54,6 @@ int CmdShorten (
|
|||
if (! ids.size ())
|
||||
throw std::string ("IDs must be specified. See 'timew help shorten'.");
|
||||
|
||||
// TODO Support :adjust
|
||||
|
||||
// Load the data.
|
||||
// Note: There is no filter.
|
||||
Interval filter;
|
||||
|
@ -63,37 +62,26 @@ int CmdShorten (
|
|||
// Apply tags to ids.
|
||||
for (auto& id : ids)
|
||||
{
|
||||
if (id <= static_cast <int> (tracked.size ()))
|
||||
{
|
||||
// Note: It's okay to subtract a one-based number from a zero-based index.
|
||||
Interval i = tracked[tracked.size () - id];
|
||||
if (! i.range.is_open ())
|
||||
{
|
||||
Duration dur (delta);
|
||||
if (dur < (i.range.end - i.range.start))
|
||||
{
|
||||
database.deleteInterval (tracked[tracked.size () - id]);
|
||||
if (id > static_cast <int> (tracked.size ()))
|
||||
throw format ("ID '@{1}' does not correspond to any tracking.", id);
|
||||
|
||||
i.range.end -= dur.toTime_t ();
|
||||
validate (cli, rules, database, i);
|
||||
database.addInterval (i);
|
||||
// Note: It's okay to subtract a one-based number from a zero-based index.
|
||||
Interval i = tracked[tracked.size () - id];
|
||||
if (i.range.is_open ())
|
||||
throw format ("Cannot shorten open interval @{1}", id);
|
||||
|
||||
// Feedback.
|
||||
if (rules.getBoolean ("verbose"))
|
||||
std::cout << "Shortened @" << id << " by " << dur.formatHours () << '\n';
|
||||
}
|
||||
else
|
||||
std::cout << "Cannot shorten interval @"
|
||||
<< id
|
||||
<< " by "
|
||||
<< dur.formatHours ()
|
||||
<< " because it is only "
|
||||
<< Duration (i.range.end - i.range.start).formatHours ()
|
||||
<< " in length.\n";
|
||||
}
|
||||
else
|
||||
std::cout << "Cannot shorten open interval @" << id << '\n';
|
||||
}
|
||||
Duration dur (delta);
|
||||
if (dur >= (i.range.end - i.range.start))
|
||||
throw format ("Cannot shorten interval @{1} by {2} because it is only {3} in length.", id, dur.formatHours (), Duration (i.range.end - i.range.start).formatHours ());
|
||||
|
||||
database.deleteInterval (tracked[tracked.size () - id]);
|
||||
|
||||
i.range.end -= dur.toTime_t ();
|
||||
validate (cli, rules, database, i);
|
||||
database.addInterval (i);
|
||||
|
||||
if (rules.getBoolean ("verbose"))
|
||||
std::cout << "Shortened @" << id << " by " << dur.formatHours () << '\n';
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue