-- This module implements {{British regnal year}}. It converts a year in the Gregorian-- calendar to the equivalent English or British regnal year.localdata=mw.loadData('Module:British regnal year/data')localp={}functionp.main(frame)-- If we are being called from #invoke, then the year is the first positional-- argument. If not, it is the frame parameter.localinputYearifframe==mw.getCurrentFrame()theninputYear=frame:getParent().args[1]localframeArgsYear=frame.args[1]ifframeArgsYeartheninputYear=frameArgsYearendelseinputYear=frameend-- Convert the input to an integer if possible. Return "N/A" if the input could-- not be converted, or if the converted input is too big or too small.iftype(inputYear)~='number'theninputYear=tonumber(inputYear)endifnotinputYearthenreturn"''N/A''"endlocalcurrentYear=tonumber(mw.language.getContentLanguage():formatDate('Y'))ifinputYear<1066orinputYear>currentYearthenreturn"''N/A''"end-- Find the year in the data page and display the output.for_,tinipairs(data)dolocaldataYear=t.yearifinputYear>=dataYearthen-- Get data values from the data page.localstartYear=t.startYearlocalcurrentRegnalYear=inputYear-dataYear+startYearlocallinkCurrent=t.linkCurrentlocalprevEndYear=t.prevEndYearlocallinkPrev=t.linkPrevlocalnote=t.noteifinputYear>dataYearthen-- Years with the same monarch.returnmw.ustring.format('%d %s – %d %s%s',currentRegnalYear-1,linkCurrent,currentRegnalYear,linkCurrent,noteor'')elseifinputYear==dataYearandprevEndYearandlinkPrevthen-- Years with a different monarch.returnmw.ustring.format('%d %s – %d %s%s',prevEndYear,linkPrev,currentRegnalYear,linkCurrent,noteor'')else-- This should only match the year 1066.returnmw.ustring.format('%d %s%s',currentRegnalYear,linkCurrent,noteor'')endendendendreturnp