mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
CmdShorten: Added 'shorten' command
This commit is contained in:
parent
9215b2362f
commit
75ff47760b
1 changed files with 39 additions and 1 deletions
|
@ -25,6 +25,7 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <cmake.h>
|
||||
#include <Duration.h>
|
||||
#include <commands.h>
|
||||
#include <timew.h>
|
||||
#include <iostream>
|
||||
|
@ -36,7 +37,44 @@ int CmdShorten (
|
|||
Rules& rules,
|
||||
Database& database)
|
||||
{
|
||||
std::cout << "# CmdShorten\n";
|
||||
// Gather IDs and TAGs.
|
||||
std::vector <int> ids;
|
||||
std::string delta;
|
||||
for (auto& arg : cli._args)
|
||||
{
|
||||
if (arg.hasTag ("ID"))
|
||||
ids.push_back (strtol (arg.attribute ("value").c_str (), NULL, 10));
|
||||
|
||||
if (arg.hasTag ("FILTER") &&
|
||||
arg._lextype == Lexer::Type::duration)
|
||||
delta = arg.attribute ("raw");
|
||||
}
|
||||
|
||||
// TODO Support :adjust
|
||||
|
||||
// Load the data.
|
||||
// Note: There is no filter.
|
||||
Interval filter;
|
||||
auto tracked = getTracked (database, rules, filter);
|
||||
|
||||
// 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];
|
||||
|
||||
Duration dur (delta);
|
||||
i.range.end -= dur.toTime_t ();
|
||||
|
||||
database.modifyInterval (tracked[tracked.size () - id], i);
|
||||
|
||||
// Feedback.
|
||||
std::cout << "Shortened @" << id << " by " << dur.formatHours () << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue