Handles jumps of >=3h

This commit is contained in:
Per Malmberg 2018-03-13 01:23:50 -07:00
parent e99b049d2b
commit 97a0a5a9c2
2 changed files with 8 additions and 8 deletions

View File

@ -114,7 +114,7 @@ namespace libcron
{
first_tick = false;
}
else if (now - last_tick < hours{3})
else if (now > last_tick && now - last_tick <= hours{3})
{
// Reschedule all tasks.
for (auto& t : tasks.get_tasks())
@ -122,7 +122,7 @@ namespace libcron
t.calculate_next(now);
}
}
else if(now < last_tick && now >= last_tick - hours{3})
else if(now < last_tick && now - last_tick < hours{3})
{
// Prevent tasks from running until the clock has reached current 'last_tick'.
for (auto& t : tasks.get_tasks())

View File

@ -248,7 +248,7 @@ SCENARIO("Clock changes")
REQUIRE(c.tick() == 1);
REQUIRE(c.tick() == 0);
REQUIRE(c.tick() == 0);
clock.add(minutes{30}); // 01:30
clock.add(minutes{30}); // 01:30
REQUIRE(c.tick() == 0);
clock.add(minutes{15}); // 01:45
REQUIRE(c.tick() == 0);
@ -261,16 +261,16 @@ SCENARIO("Clock changes")
THEN("Task are rescheduled, not run")
{
REQUIRE(c.tick() == 1);
std::cout << c << std::endl;
std::cout << "0: " << c << std::endl;
clock.add(hours{3}); // 03:00
REQUIRE(c.tick() == 1); // Rescheduled
std::cout << c << std::endl;
std::cout << "1: " << c << std::endl;
clock.add(minutes{15}); // 03:15
REQUIRE(c.tick() == 1);
std::cout << c << std::endl;
REQUIRE(c.tick() == 0);
std::cout << "2: " << c << std::endl;
clock.add(minutes{45}); // 04:00
REQUIRE(c.tick() == 1);
std::cout << c << std::endl;
std::cout << "3: " << c << std::endl;
}
}