Posts: 61
Threads: 22
Joined: Sep 2022
Reputation:
2
26.05.2026, 09:02
(This post was last modified: 26.05.2026, 09:03 by Ceros2112.)
Hello,
one of my customer is asking if there is a way to change the holidays calendar automatically by year (let' s pretend that I can retrieve this information somehow  )
for example: he wants to change the holiday schedule automatically with every non working day in Italy in 2026, next year it will be updated.
I know, it's a crazy request.
Thank you for your help.
Posts: 8793
Threads: 48
Joined: Jun 2015
Reputation:
502
Posts: 61
Threads: 22
Joined: Sep 2022
Reputation:
2
Posts: 61
Threads: 22
Joined: Sep 2022
Reputation:
2
Another strange request, sorry, is there a way to determine whether today is the first day following a scheduled non working period in the holiday calendar, and how long that period lasted?
Many thanks
Posts: 5701
Threads: 30
Joined: Aug 2017
Reputation:
252
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
Posts: 61
Threads: 22
Joined: Sep 2022
Reputation:
2
|