From b14e997ae44060c5043179f7fe40bda8beaecef5 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 24 Jul 2016 10:46:24 -0400 Subject: [PATCH] CmdLengthen: Cleanup --- src/commands/CmdLengthen.cpp | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/src/commands/CmdLengthen.cpp b/src/commands/CmdLengthen.cpp index 0fba41f2..5f46fe64 100644 --- a/src/commands/CmdLengthen.cpp +++ b/src/commands/CmdLengthen.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -53,8 +54,6 @@ int CmdLengthen ( if (! ids.size ()) throw std::string ("IDs must be specified. See 'timew help lengthen'."); - // TODO Support :adjust - // Load the data. // Note: There is no filter. Interval filter; @@ -63,26 +62,23 @@ int CmdLengthen ( // Apply tags to ids. for (auto& id : ids) { - if (id <= static_cast (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 ()) - { - database.deleteInterval (tracked[tracked.size () - id]); + if (id > static_cast (tracked.size ())) + throw format ("ID '@{1}' does not correspond to any tracking.", id); - Duration dur (delta); - 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 lengthen open interval @{1}", id); - // Feedback. - if (rules.getBoolean ("verbose")) - std::cout << "Lengthened @" << id << " by " << dur.formatHours () << '\n'; - } - else - std::cout << "Cannot lengthen open interval @" << id << '\n'; - } + database.deleteInterval (tracked[tracked.size () - id]); + + Duration dur (delta); + i.range.end += dur.toTime_t (); + validate (cli, rules, database, i); + database.addInterval (i); + + if (rules.getBoolean ("verbose")) + std::cout << "Lengthened @" << id << " by " << dur.formatHours () << '\n'; } return 0;