diff --git a/src/commands/CmdStart.cpp b/src/commands/CmdStart.cpp index 5a7d4dc5..efd8f020 100644 --- a/src/commands/CmdStart.cpp +++ b/src/commands/CmdStart.cpp @@ -45,9 +45,12 @@ int CmdStart ( auto latest = getLatestInterval (database); if (latest.range.is_open ()) { - // Stop it. + // Stop it, at the given start time, if applicable. Interval modified {latest}; - modified.range.end = Datetime (); + if (filter.range.start.toEpoch () != 0) + modified.range.end = filter.range.start; + else + modified.range.end = Datetime (); // Update database. database.deleteInterval (latest); diff --git a/test/start.t b/test/start.t index 1232bc98..b459403c 100755 --- a/test/start.t +++ b/test/start.t @@ -79,6 +79,16 @@ class TestStart(TestCase): self.assertIn("Recorded foo", out) self.assertIn("Tracking bar", out) + def test_start_with_open_interval_timed(self): + """Test timed start with already open interval, which should be auto-stopped + at given datetime""" + self.t("start 2016-01-01T00:00:00 foo") + code, out, err = self.t("start 2016-01-01T01:00:00 bar") + self.assertIn("Recorded foo", out) + self.assertIn("Tracking bar", out) + + self.assertIn("Ended 01:00:00",out) + if __name__ == "__main__": from simpletap import TAPTestRunner unittest.main(testRunner=TAPTestRunner())