27.05.2026, 12:19
Try this script, it will log the info but you can aslo write it to object.
Code:
local function fetch_holidays()
local rows = db:getall('SELECT year, month, day, name, duration FROM scheduler_holidays ORDER BY year, month, day')
if type(rows) ~= 'table' or #rows == 0 then
log('holiday monitor: scheduler_holidays table is empty or not accessible')
return {}
end
local entries = {}
for _, row in ipairs(rows) do
local year = tonumber(row.year)
local month = tonumber(row.month)
local day = tonumber(row.day)
local name = row.name or 'Holiday'
local duration = tonumber(row.duration) or 1
if year and month and day then
table.insert(entries, {
year = year,
month = month,
day = day,
name = name,
duration = duration,
})
end
end
return entries
end
local function build_periods(entries)
local periods = {}
for _, entry in ipairs(entries) do
local start_ts = os.time({ year = entry.year, month = entry.month, day = entry.day, hour = 12 })
local end_ts = start_ts + (entry.duration - 1) * 24 * 60 * 60
table.insert(periods, {
name = entry.name,
start_ts = start_ts,
end_ts = end_ts,
start_year = entry.year,
start_month = entry.month,
start_day = entry.day,
end_year = os.date('*t', end_ts).year,
end_month = os.date('*t', end_ts).month,
end_day = os.date('*t', end_ts).day,
duration = entry.duration,
})
end
table.sort(periods, function(a, b)
return a.start_ts < b.start_ts
end)
return periods
end
local entries = fetch_holidays()
if #entries == 0 then
log('holiday monitor: no scheduled holidays found in database')
return
end
local periods = build_periods(entries)
if #periods == 0 then
log('holiday monitor: could not build holiday periods')
return
end
local today = os.date('*t')
local today_ts = os.time({ year = today.year, month = today.month, day = today.day, hour = 12 })
local yesterday_ts = today_ts - 24 * 60 * 60
local candidate = nil
for _, period in ipairs(periods) do
if period.end_ts == yesterday_ts then
candidate = period
break
end
end
if candidate then
log(string.format(
'Today is the first working day after scheduled non-working period "%s" from %04d-%02d-%02d to %04d-%02d-%02d lasting %d day(s)',
candidate.name,
candidate.start_year, candidate.start_month, candidate.start_day,
candidate.end_year, candidate.end_month, candidate.end_day,
candidate.duration
))
else
log('holiday monitor: no scheduled non-working period ended yesterday')
end
------------------------------
Ctrl+F5
Ctrl+F5