Module:Sandbox/Valwren

From Fallen London Wiki

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

--Place to put Lua text for modules, for sandbox
-- CURRENTLY TESTING - sacroboscan fix
-- Based on 'Module:RatWeekend' by [[User:Tirerim]]
local p = {}

local function event_start_for_time(time)
  local weekday = os.date("%w", time)
  
  -- the below does NOT work
  --if weekday == '1' or weekday == '2' or weekday == '3' or (weekday == '4' and os.date("%H%M", time) < '1200') then
	--thursday = thursday + (7 * 86400)
  --end
  --return thursday
  
  -- the below does NOT work
 -- if weekday == '1' or weekday == '2' or weekday == '3' or (weekday == '4' and os.date("%H%M", time) < '1200') then
    --monday = monday - (7 * 86400)
  --end
  --return monday
  
  -- the below works correctly
  local thursday = (4 - weekday) * 86400 + time
	thursday = thursday - (7 * 86400)
  return thursday
  
end

local function date_for_offset(offset)
  local current_time = os.time()
  local start_day = event_start_for_time(current_time)
  start_day = start_day + (offset * 7 * 86400)
  local end_day = start_day + (7 * 86400)
  return os.date("%b&nbsp;%d", start_day) .. '&nbsp;- ' .. os.date("%b&nbsp;%d", end_day)end

function p.event_time(frame)
  local current_event = frame.args[1]
  local future_event = frame.args[2]
  local offset = (tonumber(future_event) - tonumber(current_event)) % 9
  return date_for_offset(offset)
end

return p