This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Automatic holidays calendar
#1
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  Confused )

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.
Reply
#2
See this: https://kb.logicmachine.net/scripting/sc...-holidays/
Reply
#3
thanks
Reply
#4
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
Reply
#5
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
Reply
#6
Thank you very much
Reply


Forum Jump: