Module:Tirerim/sandbox/RatWeekend
From Fallen London Wiki
Documentation for this module may be created at Module:Tirerim/sandbox/RatWeekend/doc
local p = {}
local function season_offset(current_season, future_season)
local seasons = {
['Freeze-and-Fall'] = 0,
['Lying-Longing'] = 1,
['Candle-Canker'] = 2,
['Wink-and-Wane'] = 3,
['Vial-Vane'] = 4,
['Take-and-Toil'] = 5,
['Wine-Whisper'] = 6,
['Rise-and-Rake'] = 7,
['Nitre-Knife'] = 8,
['Kifer-Caitiff'] = 9,
['Skitter-Scatter'] = 10,
['Dimmest-Dark'] = 11
}
local offset = ( seasons[future_season] - seasons[current_season] ) % 12
return offset
end
-- since we only care about whole days, we can just add/subtract days worth of seconds to/from epoch time
local function rat_start_for_time(time)
local weekday = os.date("%w", time)
local friday = (5 - weekday) * 86400 + time
if (weekday == '1' and os.date("%H%M", time) < '1100') or weekday == '0' then
friday = friday - (7 * 86400)
end
return friday
end
local function date_for_offset(offset)
local current_time = os.time()
local start_day = rat_start_for_time(current_time) + (offset * 7 * 86400)
local end_day = start_day + (3 * 86400)
return os.date("%b %d", start_day) .. ' - ' .. os.date("%b %d", end_day)
end
-- given the current Rat-Season and some future Rat-Season (possibly identical),
-- calculates the dates when it will next (or currently) occur
function p.weekend(frame)
local current_season = frame.args[1]
local future_season = frame.args[2]
local offset = season_offset(current_season, future_season)
return date_for_offset(offset)
end
return p