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' } -- The months of the year, as numbers local monthNumber = { ['Hammer']    = 1, ['Alturiak']  = 2, ['Ches']      = 3, ['Tarsakh']   = 4, ['Mirtul']    = 5, ['Kythorn']   = 6, ['Flamerule'] = 7, ['Eleasis']   = 8, ['Eleasias']  = 8, ['Eleint']    = 9, ['Marpenoth'] = 10, ['Uktar']     = 11, ['Nightal']   = 12 }

local function addPhases(phases, phaseL) --   local ph = phases local phaseIndex = 1 for dayNum in mw.text.gsplit(phaseL, ',', true) do       table.insert(phases, tonumber(dayNum), phaseSymbols[phaseIndex]) phaseIndex = phaseIndex + 1 end --   return #phases..' '..phaseL end

local function buildPhaseList(frame, FRmonth, yearsSinceLeap) local currMonth = monthNumber[FRmonth] local currYear = 2004 + yearsSinceLeap local prevMonth, prevYear, nextMonth, nextYear = 0, 0, 0, 0 local currPhaseDate = tostring(currYear)..'-'..currMonth..'-15' local currPhaseList = frame:expandTemplate({title = 'Selune phase',                                                args  = {mode='fivePhases', currPhaseDate}}) --   if currMonth - 1 < 1 then --       prevMonth = 12 --       prevYear = currYear - 1 --   else --       prevMonth = currMonth - 1 --       prevYear  = currYear --   end --   local prevPhaseDate = tostring(prevYear)..'-'..prevMonth..'-15' --   local prevPhaseList = frame:expandTemplate({title = 'Selune phase', --                                                args  = {mode='fivePhases', prevPhaseDate}}) --   if currMonth + 1 > 12 then --       nextMonth = 1 --       nextYear = currYear + 1 --   else --       nextMonth = currMonth + 1 --       nextYear  = currYear --   end --   local nextPhaseDate = tostring(nextYear)..'-'..nextMonth..'-15' --   local nextPhaseList = frame:expandTemplate({title = 'Selune phase', --                                                args  = {mode='fivePhases', nextPhaseDate}}) local phases = {} --   table.insert(phases, addPhases(phases, prevPhaseList)) addPhases(phases, currPhaseList) --   table.insert(phases, addPhases(phases, nextPhaseList)) return phases[776]..', '..currPhaseList end local function getMonthHtml(FRmonth, phaseDay, phases) local altLink = '' local rows = mw.html.create('') for tenday = 0, 2 do       rows:tag('tr') for day = 1, 10 do           altLink = phases[phaseDay] or tostring(day + 10*tenday) rows:tag('td'):wikitext(..altLink..):done phaseDay = phaseDay + 1 end rows:done end return tostring(rows) end

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 yearsSinceLeap = ((FRyear % 4) + 4) % 4 local leapYear = (yearsSinceLeap == 0) local dsl = frame:expandTemplate({title = 'Date number', args = {FRdate, FRyear}}) --   local phaseTable = buildPhaseList(frame, FRmonth, yearsSinceLeap) return buildPhaseList(frame, FRmonth, yearsSinceLeap) --   local title = getYearName(FRyear) == '' and 'Calendar of Harptos' or getYearName(FRyear) -- --   local phaseDay = dsl - FRday + 1 -- --   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(getMonthHtml(FRmonth, phaseDay, phaseTable)) --         :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..' '..yearsSinceLeap..' '..tostring(leapYear) -- end

return FRCalendar