CmdStart: Do not assume :all hint means now

Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
This commit is contained in:
Shaun Ruffell 2020-06-07 23:12:59 -05:00 committed by Thomas Lauf
parent 6a52a412ba
commit 4aacba47df
2 changed files with 14 additions and 8 deletions

View file

@ -36,23 +36,25 @@ int CmdStart (
Journal& journal) Journal& journal)
{ {
auto verbose = rules.getBoolean ("verbose"); auto verbose = rules.getBoolean ("verbose");
const Datetime now {};
auto filter = cli.getFilter (); auto filter = cli.getFilter ({now, 0});
auto now = Datetime ();
if (filter.start > now) if (filter.start > now)
{
throw std::string ("Time tracking cannot be set in the future."); throw std::string ("Time tracking cannot be set in the future.");
}
else if (!filter.is_started ())
{
// The :all hint provides a filter that is neither started nor ended, which
// the start command cannot handle and we do not want to auto start it now.
throw std::string ("Interval start must be specified");
}
auto latest = getLatestInterval (database); auto latest = getLatestInterval (database);
journal.startTransaction (); journal.startTransaction ();
if (!filter.is_started ())
{
filter.start = now;
}
// If the latest interval is open, close it. // If the latest interval is open, close it.
if (latest.is_open ()) if (latest.is_open ())
{ {

View file

@ -263,6 +263,10 @@ class TestStart(TestCase):
code, out, err = self.t.runError("start 2h ago proja") code, out, err = self.t.runError("start 2h ago proja")
self.assertIn("The end of a date range must be after the start.", err) self.assertIn("The end of a date range must be after the start.", err)
def test_start_will_error_with_all_hint(self):
"""Start will return an error when passed the :all hint"""
code, out, err = self.t.runError("start :all proja")
if __name__ == "__main__": if __name__ == "__main__":
from simpletap import TAPTestRunner from simpletap import TAPTestRunner