mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-06-26 10:54:28 +02:00
Extract function CLI::getDuration ()
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
This commit is contained in:
parent
0c1d7291e2
commit
e8511c5efd
5 changed files with 22 additions and 32 deletions
17
src/CLI.cpp
17
src/CLI.cpp
|
@ -34,6 +34,7 @@
|
|||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include <Duration.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
A2::A2 (const std::string& raw, Lexer::Type lextype)
|
||||
|
@ -589,3 +590,19 @@ std::string CLI::getAnnotation () const
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Duration CLI::getDuration () const
|
||||
{
|
||||
std::string delta;
|
||||
for (auto& arg : _args)
|
||||
{
|
||||
if (arg.hasTag ("FILTER") &&
|
||||
arg._lextype == Lexer::Type::duration)
|
||||
{
|
||||
delta = arg.attribute ("raw");
|
||||
}
|
||||
}
|
||||
Duration dur (delta);
|
||||
return dur;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <set>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <Duration.h>
|
||||
|
||||
// Represents a single argument.
|
||||
class A2
|
||||
|
@ -68,6 +69,7 @@ public:
|
|||
std::set <int> getIds () const;
|
||||
std::vector<std::string> getTags () const;
|
||||
std::string getAnnotation() const;
|
||||
Duration getDuration() const;
|
||||
std::string dump (const std::string& title = "CLI Parser") const;
|
||||
|
||||
private:
|
||||
|
@ -86,4 +88,3 @@ public:
|
|||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -49,16 +49,7 @@ int CmdLengthen (
|
|||
throw std::string ("IDs must be specified. See 'timew help lengthen'.");
|
||||
}
|
||||
|
||||
std::string delta;
|
||||
|
||||
for (auto& arg : cli._args)
|
||||
{
|
||||
if (arg.hasTag ("FILTER") &&
|
||||
arg._lextype == Lexer::Type::duration)
|
||||
{
|
||||
delta = arg.attribute ("raw");
|
||||
}
|
||||
}
|
||||
Duration dur = cli.getDuration ();
|
||||
|
||||
journal.startTransaction ();
|
||||
|
||||
|
@ -75,7 +66,6 @@ int CmdLengthen (
|
|||
|
||||
database.deleteInterval (interval);
|
||||
|
||||
Duration dur (delta);
|
||||
interval.end += dur.toTime_t ();
|
||||
validate (cli, rules, database, interval);
|
||||
database.addInterval (interval, verbose);
|
||||
|
|
|
@ -48,15 +48,7 @@ int CmdResize (
|
|||
throw std::string ("IDs must be specified. See 'timew help resize'.");
|
||||
}
|
||||
|
||||
std::string delta;
|
||||
for (auto& arg : cli._args)
|
||||
{
|
||||
if (arg.hasTag ("FILTER") &&
|
||||
arg._lextype == Lexer::Type::duration)
|
||||
{
|
||||
delta = arg.attribute ("raw");
|
||||
}
|
||||
}
|
||||
Duration dur = cli.getDuration ();
|
||||
|
||||
journal.startTransaction ();
|
||||
|
||||
|
@ -70,7 +62,6 @@ int CmdResize (
|
|||
throw format ("Cannot resize open interval @{1}", interval.id);
|
||||
}
|
||||
|
||||
Duration dur (delta);
|
||||
database.deleteInterval (interval);
|
||||
|
||||
interval.end = interval.start + dur.toTime_t ();
|
||||
|
|
|
@ -48,15 +48,7 @@ int CmdShorten (
|
|||
throw std::string ("IDs must be specified. See 'timew help shorten'.");
|
||||
}
|
||||
|
||||
std::string delta;
|
||||
for (auto& arg : cli._args)
|
||||
{
|
||||
if (arg.hasTag ("FILTER") &&
|
||||
arg._lextype == Lexer::Type::duration)
|
||||
{
|
||||
delta = arg.attribute ("raw");
|
||||
}
|
||||
}
|
||||
Duration dur = cli.getDuration ();
|
||||
|
||||
journal.startTransaction ();
|
||||
|
||||
|
@ -71,7 +63,6 @@ int CmdShorten (
|
|||
throw format ("Cannot shorten open interval @{1}", interval.id);
|
||||
}
|
||||
|
||||
Duration dur (delta);
|
||||
if (dur > (interval.end - interval.start))
|
||||
{
|
||||
throw format ("Cannot shorten interval @{1} by {2} because it is only {3} in length.",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue