Module:Timetable

From Nasqueron Agora

Documentation for this module may be created at Module:Timetable/doc

local p = {}

function p.generateTimeList(weekday, start, finish)
  -- Define the time zones
  local utcOffset = 0
  local cestOffset = 2
  local mdtOffset = -6

  -- Parse the start and end times
  local startHour, startMinute = start:match("(%d+):(%d+)")
  local endHour, endMinute = finish:match("(%d+):(%d+)")
  
  -- Convert the start and end times to integers
  startHour = tonumber(startHour)
  startMinute = tonumber(startMinute)
  endHour = tonumber(endHour)
  endMinute = tonumber(endMinute)
  
  -- Calculate the adjusted start and end times for each time zone
  local utcStartHour = startHour
  local utcEndHour = endHour
  local cestStartHour = (startHour + cestOffset) % 24
  local cestEndHour = (endHour + cestOffset) % 24
  local mdtStartHour = (startHour + mdtOffset) % 24
  local mdtEndHour = (endHour + mdtOffset) % 24

  -- Adjust the day for time zones ahead of UTC
  if cestStartHour < startHour then
    weekday = (weekday + 1) % 7
  end
  
  if mdtStartHour < startHour then
    weekday = (weekday - 1) % 7
  end

  -- Format the output strings
  local output = {}
  local weekdayNames = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}
  
  output[1] = string.format("* %s %02d:%02d-%02d:%02d (UTC)", weekdayNames[weekday + 1], startHour, startMinute, endHour, endMinute)
  output[2] = string.format("* %s %02d:%02d-%02d:%02d (UTC+%d, CEST, Brussels)", weekdayNames[weekday + 1], cestStartHour, startMinute, cestEndHour, endMinute, cestOffset)
  output[3] = string.format("* %s %02d:%02d-%02d:%02d (UTC%d, MDT, Edmonton)", weekdayNames[(weekday - 1) % 7 + 1], mdtStartHour, startMinute, mdtEndHour, endMinute, mdtOffset)
 
  mw.logObject(output)
 
  return table.concat(output, "\n")
end

return p