From d268168dc7f723f3afe07105b3b765f6bde2ef2e Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Mon, 7 Aug 2023 18:08:53 +1000 Subject: [PATCH] fix(server/cron): invalid step return for indivisible values Was reliant on some previously removed hacky-logic in scheduleTask. Return value + max and rely on getNextTime/os.time to handle overflow. --- imports/cron/server.lua | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/imports/cron/server.lua b/imports/cron/server.lua index dacf37517..bab114126 100644 --- a/imports/cron/server.lua +++ b/imports/cron/server.lua @@ -52,16 +52,15 @@ local function getTimeUnit(value, unit) local stepValue = string.match(value, '*/(%d+)') if stepValue then + -- */10 * * * * is equal to a list of 0,10,20,30,40,50 + -- best suited to factors of unitMax (excluding the highest and lowest numbers) + -- i.e. for minutes - 2, 3, 4, 5, 6, 10, 12, 15, 20, 30 for i = currentTime + 1, unitMax do - -- return the current minute if it is divisible by the stepvalue - -- i.e. */10 * * * * is equal to a list of 0,10,20,30,40,50 - -- best suited to numbers evenly divided by unitMax - if i % stepValue == 0 then - return i - end + -- if i is divisible by stepValue + if i % stepValue == 0 then return i end end - return 0 + return stepValue + unitMax end local range = string.match(value, '%d+-%d+')