Skip to content

Commit 07802a5

Browse files
committed
test/continue: Check continue with a future datetime
Signed-off-by: Shaun Ruffell <[email protected]>
1 parent b8611a1 commit 07802a5

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/commands/CmdContinue.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,10 @@ int CmdContinue (
3838
Journal& journal)
3939
{
4040
const bool verbose = rules.getBoolean ("verbose");
41-
const Datetime now {};
42-
43-
auto filter = cli.getFilter ({ now, 0 });
44-
45-
if (filter.start > now)
46-
{
47-
throw std::string ("Time tracking cannot be set in the future.");
48-
}
4941

42+
// Gather IDs and TAGs.
5043
std::set <int> ids = cli.getIds ();
44+
auto filter = cli.getFilter ();
5145

5246
if (!ids.empty () && !filter.tags().empty ())
5347
{

test/continue.t

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import os
3030
import sys
3131
import unittest
3232

33-
from datetime import datetime, timedelta
33+
from datetime import datetime, timedelta, timezone
3434

3535
# Ensure python finds the local simpletap module
3636
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
@@ -504,7 +504,7 @@ class TestContinue(TestCase):
504504

505505
def test_continue_with_future_time(self):
506506
"""Verify that continue fails with time in the future"""
507-
now_utc = datetime.now().utcnow()
507+
now_utc = datetime.now(timezone.utc)
508508

509509
one_hour_before_utc = now_utc - timedelta(hours=1)
510510
two_hours_before_utc = now_utc - timedelta(hours=2)
@@ -516,8 +516,9 @@ class TestContinue(TestCase):
516516
code, out, err = self.t("stop")
517517
self.assertIn("Recorded BAR\n", out)
518518

519-
code, out, err = self.t.runError("continue @2 from {:%Y-%m-%dT%H:%M:%S}Z".format(now_utc + timedelta(seconds=10)))
520-
self.assertIn("Time tracking cannot be set in the future", err)
519+
input_time_utc = now_utc + timedelta(seconds=10)
520+
code, out, err = self.t("continue @2 from {:%Y-%m-%dT%H:%M:%S}Z".format(input_time_utc))
521+
self.assertIn("Scheduled for {:%Y-%m-%dT%H:%M:%S}".format(input_time_utc.astimezone()), out)
521522

522523

523524
if __name__ == "__main__":

0 commit comments

Comments
 (0)