if type( s ) ~= 'string' or s == '' then return end
self.link = s
end  
function calendar:getLink
-- Returns the calendar's link value.
return self.link
end  
function calendar:setYear( year )
-- Sets a single year. Can be passed either a string or a number.
-- If passed as a number, it is formatted with minus signs instead of hyphens.
-- If passed as a string, no minus-sign formatting occurs; this should be done in the individual calendar definitions.
if type( year ) == 'number' then
year = tostring( year )
self.year = formatNegative( year )
elseif type( year ) == 'string' then
self.year = year
end
end  
function calendar:setYearRange( year1, year2 )
-- Sets a year range. Must be passed two numbers.
if type( year1 ) == 'number' and type( year2 ) == 'number' then
local year
if year1 < 0 or year2 < 0 then -- Leave a gap for negative years to avoid having a minus sign and a dash next to each other.
year = string.format( '%d – %d', year1, year2 )
year = formatNegative( year )
else
year = string.format( '%d–%d', year1, year2 )
end
self.year = year
end
end  
function calendar:setYearCouple( year1, year2, addtext )
-- Same as setYearRange, only with a slash (/) in the middle. Must be passed two numbers.
-- Additional text possible, must be defined as follows: addtext = string.format( 'additional text or link')
-- See example in Seleucid era calendar
if type( year1 ) == 'number' and type( year2 ) == 'number' then
local year
if year1 < 0 or year2 < 0 then -- Leave no gap for negative years.
year = string.format( '%d/%d %s', year1, year2, addtext )
year = formatNegative( year )
else
year = string.format( '%d/%d %s', year1, year2, addtext )
end
self.year = year
end
end  
function calendar:export
-- Outputs the calendar wikitext.
-- Exit if no link has been specified.
local link = self.link
if type( link ) ~= 'string' or link == '' then return end  
-- If no year has been specified, set the year value to N/A.
local year = self.year
if type( year ) ~= 'string' or year == '' then
year = "*N/A*"
end  
-- Build the table row.
local ret = mw.html.create
ret
:tag( 'tr' )
:tag( 'td' )
:wikitext( link )
:done
:tag( 'td' )
:wikitext( year )
:allDone
return tostring( ret )
end  
---
-- Build the box
---  
local function makeCalendarBox( args )
-- Initiate the box and get the year values.
local init = args
local box = calendarBox:new( init )
local year = box.year
local yearText = box.yearText  
-- Set the caption.
box:setCaption( box.caption .. ' in various calendars' )  
---
-- Gregorian calendar
---  
local gregorian = calendar:new
gregorian:setLink( 'கிரெகொரியின் நாட்காட்டி' )
-- Get the year link.
local gregcal = args.gregcal
if type( gregcal ) == 'string' and gregcal ~= '' then
gregorian.yearLink = string.format( '%s', gregcal, yearText )
else
gregorian.yearLink = yearText
end
-- Set the year.
gregorian.romanYear = numToRoman{ math.abs(year) } .. (year < 0 and ' BC' or '')
if gregorian.romanYear then
gregorian:setYear( string.format(
%s
<span>*%s*</span>,
gregorian.yearLink, gregorian.romanYear
) )
else
gregorian:setYear( gregorian.yearLink )
end
box:addCalendar( gregorian )  
---
-- French Republican calendar
-- displays only in years 1793 - 1805 and 1871
-- This calendar was in use and had defined years only for the short period on display.
-- Its importance during these few years is also the reason why it should stay out of the alphabetic order.
-- See discussion on talk page.
---  
if year >= 1793 and year < 1806 or year == 1871 then
local republican = calendar:new
republican:setLink('French Republican calendar')
if year <= 1870 then
republican:setYearRange( year - 1792, year - 1791 )
elseif year == 1871 then
republican:setYear( year - 1792 ) -- Paris Commune, May
end
box:addCalendar( republican )
end  
---
-- திருவள்ளுவர் ஆண்டு
-- Gregorian +31 years
---
local ThiruAandu = calendar:new
ThiruAandu:setLink( 'திருவள்ளுவர் ஆண்டு' )
ThiruAandu:setYear( year + 31 )
box:addCalendar( ThiruAandu )  
---
-- Ab urbe condita
-- Varro's correlation, from 1 AUC
---
if year >= -752 then
local abUrbe = calendar:new
abUrbe:setLink( 'அப் ஊர்பி கொண்டிட்டா' )
abUrbe:setYear( year + 753 )
box:addCalendar( abUrbe )
end  
---
-- Ancient Egypt era
-- Displays dynasty between 1549 BC and 30 BC
-- Displays pharaoh or king between 752 BC and 30 BC
---
if year > -1549 and year <= -29 then
local ancEgypt = calendar:new
ancEgypt:setLink(
'Egyptian chronology',
'Ancient Egypt era'
ancEgypt:setYear( getDynasty( year ) )
box:addCalendar( ancEgypt )
end
if year > - 752 and year <= -29 then
local ancPharaoh = calendar:new
ancPharaoh:setLink(
'List of pharaohs',
'<i>- Pharaoh</i>'
ancPharaoh:setYear( getPharaoh( year ) )
box:addCalendar( ancPharaoh )
end  
---
-- Ancient Olympiads
-- Currently only the first 194 Olympiads
-- May be expanded until 394 AD when data available
---
if year >= -1300 and year < 1 then
local ancOlympiads = calendar:new
ancOlympiads:setLink(
'Ancient Greek calendar',
'Ancient Greek era'
ancOlympiads:setYear( getOlympiad( year ) )
box:addCalendar( ancOlympiads )
end  
---
-- Armenian calendar
---  
if year > 551 then
local armenian = calendar:new
armenian:setLink( 'அர்மீனிய நாட்காட்டி' )
local armenianYear = year - 551
armenian:setYear( string.format( '%s
ԹՎ %s', armenianYear, numToArmenian( armenianYear ) ) )
box:addCalendar( armenian )
end  
---
-- Assyrian calendar
---  
local assyrian = calendar:new
assyrian:setLink( 'அசிரிய நாட்காட்டி' )
assyrian:setYear( year + 4750 )
box:addCalendar( assyrian )  
---
-- Bahá'í calendar
-- displays only after 1843
---  
if year >= 1844 then
local bahai = calendar:new
bahai:setLink( "Baháʼí calendar" )
bahai:setYearRange( year - 1844, year - 1843 )
box:addCalendar( bahai )
end  
---
-- Balinese saka calendar
---
local balinese = calendar:new
balinese:setLink( 'Balinese saka calendar' )
if year - 76 > 0 then
balinese:setYearRange( year - 79, year - 78 )
end
box:addCalendar( balinese )  
---
-- Bengali calendar
---  
local bengali = calendar:new
bengali:setLink( 'Bengali calendar' )
bengali:setYear( year - 593 )
box:addCalendar( bengali )  
---
-- Berber calendar
---  
local berber = calendar:new
berber:setLink( 'Berber calendar' )
berber:setYear( year + 950 )
box:addCalendar( berber )  
---
-- Regnal year
---  
if year >= 1000 then
local regnal = calendar:new
local regnalName
if year > 1706 then
regnalName = 'British'
else
regnalName = 'English'
end
regnal:setLink( 'Regnal years of English monarchs', regnalName .. ' Regnal year' )
regnal:setYear( getRegnal( year ) )
box:addCalendar( regnal )
end  
---
-- Buddhist calendar
---  
local buddhist = calendar:new
buddhist:setLink( 'Buddhist calendar' )
buddhist:setYear( year + 544 )
box:addCalendar( buddhist )  
---
-- Burmese calendar
---  
local burmese = calendar:new
burmese:setLink( 'Burmese calendar' )
burmese:setYear( year - 638 )
box:addCalendar( burmese )  
---
-- Byzantine calendar
---  
local byzantine = calendar:new
byzantine:setLink( 'Byzantine calendar' )
byzantine:setYearRange( year + 5508, year + 5509 )
box:addCalendar( byzantine )  
---
-- Chinese calendar
---  
local chinese = calendar:new
chinese:setLink( 'சீன நாட்காட்டி' )  
-- Define the information for the "heavenly stems" and "earthly branches" year cycles.
-- See Chinese calendar#Cycle of years for information.  
local heavenlyStems = {
{ '甲', 'Wood' }, -- 1
{ '乙', 'Wood' }, -- 2
{ '丙', 'Fire' }, -- 3
{ '丁', 'Fire' }, -- 4
{ '戊', 'Earth' }, -- 5
{ '己', 'Earth' }, -- 6
{ '庚', 'Metal' }, -- 7
{ '辛', 'Metal' }, -- 8
{ '壬', 'Water' }, -- 9
{ '癸', 'Water' } -- 10
}  
local earthlyBranches = {
{ '子', 'Rat' }, -- 1
{ '丑', 'Ox' }, -- 2
{ '寅', 'Tiger' }, -- 3
{ '卯', 'Rabbit' }, -- 4
{ '辰', 'Dragon' }, -- 5
{ '巳', 'Snake' }, -- 6
{ '午', 'Horse' }, -- 7
{ '未', 'Goat' }, -- 8
{ '申', 'Monkey' }, -- 9
{ '酉', 'Rooster' }, -- 10
{ '戌', 'Dog' }, -- 11
{ '亥', 'Pig' } -- 12
}  
-- Calculate the cycle numbers from the year. The first sexagenary year corresponds to the *previous* year's entry