mirror of
				https://github.com/PerMalmberg/libcron.git
				synced 2025-10-30 19:48:38 -05:00 
			
		
		
		
	Handles jumps of >=3h
This commit is contained in:
		| @@ -114,7 +114,7 @@ namespace libcron | |||||||
|         { |         { | ||||||
|             first_tick = false; |             first_tick = false; | ||||||
|         } |         } | ||||||
|         else if (now - last_tick < hours{3}) |         else if (now > last_tick && now - last_tick <= hours{3}) | ||||||
|         { |         { | ||||||
|             // Reschedule all tasks. |             // Reschedule all tasks. | ||||||
|             for (auto& t : tasks.get_tasks()) |             for (auto& t : tasks.get_tasks()) | ||||||
| @@ -122,7 +122,7 @@ namespace libcron | |||||||
|                 t.calculate_next(now); |                 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'. |             // Prevent tasks from running until the clock has reached current 'last_tick'. | ||||||
|             for (auto& t : tasks.get_tasks()) |             for (auto& t : tasks.get_tasks()) | ||||||
|   | |||||||
| @@ -261,16 +261,16 @@ SCENARIO("Clock changes") | |||||||
|             THEN("Task are rescheduled, not run") |             THEN("Task are rescheduled, not run") | ||||||
|             { |             { | ||||||
|                 REQUIRE(c.tick() == 1); |                 REQUIRE(c.tick() == 1); | ||||||
|                 std::cout << c << std::endl; |                 std::cout << "0: " << c << std::endl; | ||||||
|                 clock.add(hours{3}); // 03:00 |                 clock.add(hours{3}); // 03:00 | ||||||
|                 REQUIRE(c.tick() == 1); // Rescheduled |                 REQUIRE(c.tick() == 1); // Rescheduled | ||||||
|                 std::cout << c << std::endl; |                 std::cout << "1: " << c << std::endl; | ||||||
|                 clock.add(minutes{15}); // 03:15 |                 clock.add(minutes{15}); // 03:15 | ||||||
|                 REQUIRE(c.tick() == 1); |                 REQUIRE(c.tick() == 0); | ||||||
|                 std::cout << c << std::endl; |                 std::cout << "2: " << c << std::endl; | ||||||
|                 clock.add(minutes{45}); // 04:00 |                 clock.add(minutes{45}); // 04:00 | ||||||
|                 REQUIRE(c.tick() == 1); |                 REQUIRE(c.tick() == 1); | ||||||
|                 std::cout << c << std::endl; |                 std::cout << "3: " << c << std::endl; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user