mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
TI-27: Continue tracking by ID
- Make command 'continue' process ids - Fix test: immediate start stop creates empty intervals?
This commit is contained in:
parent
ad67539f94
commit
a5dc0cd385
3 changed files with 73 additions and 18 deletions
|
@ -4,6 +4,8 @@
|
|||
(Thanks to Jörg Krause, Ben Boeckel).
|
||||
- TW-1845 Cygwin build fails, missing get_current_dir_name
|
||||
(thanks to hosaka).
|
||||
- TI-27 Continue tracking by ID
|
||||
(thanks to Dennis Schubert)
|
||||
- TI-29 timew config can't add new value
|
||||
(thanks to Yury Vidineev)
|
||||
- TI-32 taskwarrior hook script doesn't stop recording waiting task
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include <cmake.h>
|
||||
#include <commands.h>
|
||||
#include <format.h>
|
||||
#include <timew.h>
|
||||
#include <iostream>
|
||||
|
||||
|
@ -35,20 +36,71 @@ int CmdContinue (
|
|||
Rules& rules,
|
||||
Database& database)
|
||||
{
|
||||
auto latest = getLatestInterval (database);
|
||||
// Gather IDs and TAGs.
|
||||
std::vector <int> ids;
|
||||
|
||||
for (auto& arg : cli._args)
|
||||
{
|
||||
if (arg.hasTag ("ID"))
|
||||
ids.push_back (strtol (arg.attribute ("value").c_str (), NULL, 10));
|
||||
}
|
||||
|
||||
if (ids.size() > 1)
|
||||
throw std::string ("You can only specify one ID to continue.");
|
||||
|
||||
Interval to_copy;
|
||||
Interval latest = getLatestInterval (database);
|
||||
|
||||
if (ids.size() == 1)
|
||||
{
|
||||
// Load the data.
|
||||
// Note: There is no filter.
|
||||
Interval filter;
|
||||
auto tracked = getTracked (database, rules, filter);
|
||||
|
||||
if (ids[0] > static_cast <int> (tracked.size ()))
|
||||
throw format ("ID '@{1}' does not correspond to any tracking.", ids[0]);
|
||||
|
||||
to_copy = tracked[tracked.size () - ids[0]];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (latest.empty ())
|
||||
throw std::string ("There is no previous tracking to continue.");
|
||||
|
||||
if (latest.range.is_open ())
|
||||
throw std::string ("There is already active tracking.");
|
||||
|
||||
// Open an identical interval and update hte DB.
|
||||
latest.range.open ();
|
||||
validate (cli, rules, database, latest);
|
||||
database.addInterval (latest);
|
||||
to_copy = latest;
|
||||
}
|
||||
|
||||
Datetime current_time = Datetime ();
|
||||
|
||||
if (latest.range.is_open()) {
|
||||
auto filter = getFilter (cli);
|
||||
auto exclusions = getAllExclusions (rules, filter.range);
|
||||
|
||||
// Stop it, at the given start time, if applicable.
|
||||
Interval modified {latest};
|
||||
modified.range.end = current_time;
|
||||
|
||||
// Update database.
|
||||
database.deleteInterval (latest);
|
||||
for (auto& interval : flatten (modified, exclusions)) {
|
||||
database.addInterval (interval);
|
||||
|
||||
if (rules.getBoolean ("verbose"))
|
||||
std::cout << intervalSummarize (database, rules, latest);
|
||||
std::cout << '\n' << intervalSummarize (database, rules, interval);
|
||||
}
|
||||
}
|
||||
|
||||
// Open an identical interval and update the DB.
|
||||
to_copy.range.open (current_time);
|
||||
validate (cli, rules, database, to_copy);
|
||||
database.addInterval (to_copy);
|
||||
|
||||
if (rules.getBoolean ("verbose"))
|
||||
std::cout << intervalSummarize (database, rules, to_copy);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -92,16 +92,16 @@ class TestContinue(TestCase):
|
|||
|
||||
def test_continue_with_id_without_active_tracking(self):
|
||||
"""Verify that continuing a specified interval works"""
|
||||
code, out, err = self.t("start FOO")
|
||||
code, out, err = self.t("start FOO 1h ago")
|
||||
self.assertIn("Tracking FOO\n", out)
|
||||
|
||||
code, out, err = self.t("stop")
|
||||
code, out, err = self.t("stop 30min ago")
|
||||
self.assertIn("Recorded FOO\n", out)
|
||||
|
||||
code, out, err = self.t("start BAR")
|
||||
code, out, err = self.t("start BAR 30min ago")
|
||||
self.assertIn("Tracking BAR\n", out)
|
||||
|
||||
code, out, err = self.t("stop")
|
||||
code, out, err = self.t("stop 15min ago")
|
||||
self.assertIn("Recorded BAR\n", out)
|
||||
|
||||
code, out, err = self.t("continue @2")
|
||||
|
@ -109,17 +109,18 @@ class TestContinue(TestCase):
|
|||
|
||||
def test_continue_with_id_with_active_tracking(self):
|
||||
"""Verify that continuing a specified interval stops active tracking"""
|
||||
code, out, err = self.t("start FOO")
|
||||
code, out, err = self.t("start FOO 1h ago")
|
||||
self.assertIn("Tracking FOO\n", out)
|
||||
|
||||
code, out, err = self.t("stop")
|
||||
code, out, err = self.t("stop 30min ago")
|
||||
self.assertIn("Recorded FOO\n", out)
|
||||
|
||||
code, out, err = self.t("start BAR")
|
||||
code, out, err = self.t("start BAR 30min ago")
|
||||
self.assertIn("Tracking BAR\n", out)
|
||||
|
||||
code, out, err = self.t("continue @2")
|
||||
self.assertIn("Recorded BAR\nTracking FOO\n", out)
|
||||
self.assertIn("Recorded BAR\n", out)
|
||||
self.assertIn("Tracking FOO\n", out)
|
||||
|
||||
if __name__ == "__main__":
|
||||
from simpletap import TAPTestRunner
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue