Skip to content

Commit b8611a1

Browse files
committed
CmdStop: Use a more descriptive error message when stopping intervals
Signed-off-by: Shaun Ruffell <[email protected]>
1 parent 7069788 commit b8611a1

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/commands/CmdStop.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ int CmdStop (
7171
{
7272
throw std::string ("No datetime specified.");
7373
}
74-
else if (filter.start <= latest.start)
75-
{
76-
throw std::string ("The end of a date range must be after the start.");
77-
}
7874

7975
std::set <std::string> diff = {};
8076

@@ -94,6 +90,23 @@ int CmdStop (
9490
std::inserter(diff, diff.begin()));
9591
}
9692

93+
if (filter.start <= latest.start)
94+
{
95+
std::stringstream sstr;
96+
97+
sstr << "Interval";
98+
auto it = latest.tags ().cbegin ();
99+
auto end = latest.tags ().cend ();
100+
while (it != end)
101+
{
102+
sstr << " " << *it;
103+
++it;
104+
}
105+
sstr << " started at " << latest.start.toISOLocalExtended ()
106+
<< " cannot be stopped at " << filter.start.toISOLocalExtended () << '.';
107+
throw sstr.str ();
108+
}
109+
97110
journal.startTransaction ();
98111

99112
if (diff.empty ())

test/stop.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class TestStop(TestCase):
6767

6868
code, out, err = self.t.runError("stop {:%Y-%m-%dT%H:%M:%S}Z".format(one_hour_before_utc))
6969

70-
self.assertIn("The end of a date range must be after the start.", err)
70+
self.assertIn("cannot be stopped at", err)
7171

7272
j = self.t.export()
7373

0 commit comments

Comments
 (0)