From 5b1c77b8aa3d9f723b45aae62cf168f7ae750a0b Mon Sep 17 00:00:00 2001 From: Thomas Lauf Date: Wed, 19 Aug 2020 14:29:51 +0200 Subject: [PATCH] Move validation of filter range up - Use default range starting at `now` - Add check for no datetime given (rare case of e.g. `timew stop :all`) Signed-off-by: Thomas Lauf --- src/commands/CmdStop.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/commands/CmdStop.cpp b/src/commands/CmdStop.cpp index 1ea36aa4..634699ae 100644 --- a/src/commands/CmdStop.cpp +++ b/src/commands/CmdStop.cpp @@ -48,9 +48,10 @@ int CmdStop ( Journal& journal) { const bool verbose = rules.getBoolean ("verbose"); + const Datetime now {}; + auto filter = cli.getFilter ({ now, 0 }); // Load the most recent interval. - auto filter = cli.getFilter (); auto latest = getLatestInterval (database); // Verify the interval is open. @@ -66,6 +67,15 @@ int CmdStop ( "Perhaps you want the modify command?."); } + if (! filter.is_started()) + { + throw std::string ("No datetime specified."); + } + else if (filter.start <= latest.start) + { + throw std::string ("The end of a date range must be after the start."); + } + journal.startTransaction (); Interval modified {latest};