From 45362017c6695afddb04bd64f7152daf2d49cc80 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Tue, 1 Aug 2023 17:39:21 +1000 Subject: [PATCH] fix(server/cron): more scheduling woes Schedule next-day tasks. Some logic improvements and breaking changes from 8488dec. --- imports/cron/server.lua | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/imports/cron/server.lua b/imports/cron/server.lua index c4ef4e2..b2fc14f 100644 --- a/imports/cron/server.lua +++ b/imports/cron/server.lua @@ -141,12 +141,21 @@ function OxTask:getNextTime() if not hour then return end - if minute >= 60 then - minute = 0 - hour += 1 + if minute >= maxUnits.min then + if not self.hour then + hour += math.floor(minute / maxUnits.min) + end + + minute = minute % maxUnits.min end - if hour >= 24 and day then return end + if hour >= maxUnits.hour and day then + if not self.day then + day += math.floor(hour / maxUnits.hour) + end + + hour = hour % maxUnits.hour + end return os.time({ min = minute, @@ -157,7 +166,7 @@ function OxTask:getNextTime() }) end --- Get timestamp for next time to run task at any day. +---Get timestamp for next time to run task at any day. ---@return number function OxTask:getAbsoluteNextTime() local minute = getTimeUnit(self.minute, 'min')