diff --git a/src/commands/CmdSplit.cpp b/src/commands/CmdSplit.cpp index 196c238c..cce88d61 100644 --- a/src/commands/CmdSplit.cpp +++ b/src/commands/CmdSplit.cpp @@ -39,25 +39,20 @@ int CmdSplit ( Database& database, Journal& journal) { + const bool verbose = rules.getBoolean ("verbose"); std::set ids = cli.getIds (); if (ids.empty ()) throw std::string ("IDs must be specified. See 'timew help split'."); - // Load the data. - // Note: There is no filter. - Interval filter; - auto tracked = getTracked (database, rules, filter); - journal.startTransaction (); - // Apply tags to ids. - for (auto& id : ids) - { - if (id > static_cast (tracked.size ())) - throw format ("ID '@{1}' does not correspond to any tracking.", id); + std::vector intervals = getIntervalsByIds (database, rules, ids); - Interval first = tracked[tracked.size () - id]; + // Apply tags to ids. + for (const auto& interval : intervals) + { + Interval first = interval; Interval second = first; if (first.is_open ()) @@ -75,16 +70,16 @@ int CmdSplit ( second.start = midpoint; } - database.deleteInterval (tracked[tracked.size () - id]); + database.deleteInterval (interval); validate (cli, rules, database, first); - database.addInterval (first, rules.getBoolean ("verbose")); + database.addInterval (first, verbose); validate (cli, rules, database, second); - database.addInterval (second, rules.getBoolean ("verbose")); + database.addInterval (second, verbose); - if (rules.getBoolean ("verbose")) - std::cout << "Split @" << id << '\n'; + if (verbose) + std::cout << "Split @" << interval.id << '\n'; } journal.endTransaction ();