Module:HGSeason
From Fallen London Wiki
Documentation for this module may be created at Module:HGSeason/doc
local p = {}
local seasons = {
['Nascency'] = 0,
['Excess'] = 1,
['Dares'] = 2,
['Devotions'] = 3,
['Irreverences'] = 4,
['Duplicities'] = 5
}
local function first_tuesday(year, month)
local day = 1
while tonumber(os.date("%w", os.time{year=year, month=month, day=day})) ~= 2 do
day = day + 1
end
return day
end
local function add_months(year, month, plus)
month = month + plus
if month > 12 then return year+1, month-12 end
return year, month
end
function p.hgseason(frame)
local current_season = frame.args[1]
local future_season = frame.args[2]
local offset = (seasons[future_season] - seasons[current_season]) % 6
local year, month = add_months(tonumber(os.date("%Y")), tonumber(os.date("%m")), offset)
local year2, month2 = add_months(year, month, 1)
return os.date("%Y %b %d", os.time{year=year, month=month, day=first_tuesday(year, month)}) .. ' - ' .. os.date("%Y %b %d", os.time{year=year2, month=month2, day=first_tuesday(year2, month2)})
end
return p