Module:FRCalendar

local FRCalendar = {} --- imported libraries -- Parses invocation and template parameters, trims whitespace, and removes blanks. local getArgs = require('Dev:Arguments').getArgs -- Smarter boolean logic local yesno = require( 'Dev:Yesno' ) -- Hash table of 2400 year names. local getYearName = require ('Module:Years').yearName -- Hash table of five moon phases, from full moon to full moon. local phaseSymbols = {"🌕", "🌗", "🌑", "🌓", "🌕" } -- Hash table of six special days and what month of the calendar should be generated for them. local monthSpecial = { ['Midwinter']        = 'Hammer', ['Greengrass']       = 'Tarsakh', ['Midsummer']        = 'Flamerule', ['Shieldmeet']       = 'Flamerule', ['Highharvestide']   = 'Eleint', ['Feast of the Moon'] = 'Uktar' }

function FRCalendar.test( frame ) local args = getArgs(frame) local FRdate = args[1] local FRyear = tonumber(args[2]) local FRday, FRmonth = string.match(FRdate, '(%d+)%s+(%a+)') if FRday == nil then FRday  = 1 FRmonth = monthSpecial[FRdate] else FRday  = tonumber(FRday) FRmonth = tostring(FRmonth) end local dsl = frame:expandTemplate({title = 'Date number', args = {FRdate, FRyear}}) local phaseList = frame:expandTemplate({title = 'Selune phase',                                            args  = {mode='fivePhases', daysSinceLeap=tostring(dsl)}}) local phases, phaseIndex = {}, 1 for dayNum in mw.text.gsplit(phaseList, ',', true) do       table.insert(phases, tonumber(dayNum), phaseSymbols[phaseIndex]) phaseIndex = phaseIndex + 1 end local title = getYearName(FRyear) == '' and 'Calendar of Harptos' or getYearName(FRyear)

local phaseDay = dsl - FRday + 1 local altLink = '' local row1 = mw.html.create('tr') for i = 1, 10 do           altLink = phases[phaseDay] or tostring(i) row1:tag('td'):wikitext(..altLink..):done phaseDay = phaseDay + 1 end row1:done local row2 = mw.html.create('tr') for i = 11, 20 do           altLink = phases[phaseDay] or tostring(i) row2:tag('td'):wikitext(..altLink..):done phaseDay = phaseDay + 1 end row2:done local row3 = mw.html.create('tr') for i = 21, 30 do           altLink = phases[phaseDay] or tostring(i) row3:tag('td'):wikitext(..altLink..):done phaseDay = phaseDay + 1 end row3:done

local output = mw.html.create('div'):addClass('RoMcontainer') :tag('div'):addClass('RoMtop'):wikitext(''):done :tag('div'):addClass('RoMcenter') :tag('div'):addClass('RoMmiddle') :tag('table'):addClass('rollOfMonths') :tag('tr') :tag('th'):attr('colspan','10') :wikitext(title) :done :done :tag('tr') :tag('th'):attr('colspan','10') :wikitext(''..FRyear..' DR') :done :done :tag('tr') :tag('th'):attr('colspan','10') :wikitext(FRmonth) :done :done :wikitext(tostring(row1)) :wikitext(tostring(row2)) :wikitext(tostring(row3)) :done :done :done :tag('div'):addClass('RoMbottom'):wikitext(''):done :allDone return tostring(output)..FRdate..' '..FRyear..' '..dsl..' '..title..' '..phaseList..' ' ..next(phases)..' '..table.concat(phases,'/')..' '..table.concat(phaseSymbols,' / ')..' ' ..FRday..' '..FRmonth..' ' end

return FRCalendar