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 <thomas.lauf@tngtech.com>
This commit is contained in:
Thomas Lauf 2020-08-19 14:29:51 +02:00
parent 990e0772d0
commit 5b1c77b8aa

View file

@ -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};