From 149213032b9e7e01818c116db0cd096e6f494326 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Mon, 17 Jul 2023 22:48:33 +1000 Subject: [PATCH] fix(server/cron): getTimeUnit corrections Consistency between range and lists. Use different time comparisons for minute units. --- imports/cron/server.lua | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/imports/cron/server.lua b/imports/cron/server.lua index 8daa807..45967c7 100644 --- a/imports/cron/server.lua +++ b/imports/cron/server.lua @@ -65,9 +65,15 @@ local function getTimeUnit(value, unit) local min, max = string.strsplit('-', range) min, max = tonumber(min, 10), tonumber(max, 10) - if currentTime >= min and currentTime <= max then return currentTime end + if unit == 'min' then + if currentTime >= max then + return min + unitMax + end + elseif currentTime > max then + return min + unitMax + end - return min + unitMax + return currentTime < min and min or currentTime end local list = string.match(value, '%d+,%d+') @@ -77,7 +83,11 @@ local function getTimeUnit(value, unit) listValue = tonumber(listValue) -- e.g. if current time is less than in the expression 0,10,20,45 * * * * - if listValue >= currentTime then + if unit == 'min' then + if currentTime < listValue then + return listValue + end + elseif currentTime <= listValue then return listValue end end @@ -90,6 +100,10 @@ local function getTimeUnit(value, unit) end if value then + if unit == 'min' then + return value <= currentTime and value + unitMax or value + end + return value < currentTime and value + unitMax or value end