local seleucid = calendar:new
seleucid:setLink( 'Seleucid era' )
local addtext = string.format( 'AG')
seleucid:setYearCouple( year + 311, year + 312, addtext )
box:addCalendar( seleucid )
end  
---
-- Thai solar calendar
---  
local thai = calendar:new
thai:setLink( 'Thai solar calendar' )
if year >= 1941 then
thai:setYear( year + 543 )
else -- if year >= 1912 or year <= 1887 -- year started in March/April
thai:setYearRange( year + 542, year + 543 )
-- else -- Rattanakosin Era, 1888?-1912
-- thai:setYear( string.format( '%d &nbsp;– %d (Rattanakosin Era)', year - 1782 , year - 1781 ) )
end
box:addCalendar( thai )  
---
-- Tibetan calendar
---  
local tibetan = calendar:new
tibetan:setLink( 'Tibetan calendar' )  
-- Define the information for the "heavenly stems" and "earthly branches" year cycles.
-- See Tibetan calendar#Years for information.  
local heavenlyStems = {
{ '阳木', 'male Wood' }, -- 1
{ '阴木', 'female Wood' }, -- 2
{ '阳火', 'male Fire' }, -- 3
{ '阴火', 'female Fire' }, -- 4
{ '阳土', 'male Earth' }, -- 5
{ '阴土', 'female Earth' }, -- 6
{ '阳金', 'male Iron' }, -- 7
{ '阴金', 'female Iron' }, -- 8
{ '阳水', 'male Water' }, -- 9
{ '阴水', 'female 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
-- in Tibetan calendar correspondence table, as the Tibetan New Year doesn't happen until Feb/Mar in
-- Gregorian years.
local sexagenaryYear1 = ( year - 4 ) % 60
local sexagenaryYear2 = ( year - 3 ) % 60
local heavenlyNum1 = (sexagenaryYear1 - 1) % 10 + 1 -- amod, since lua arrays are 1-indexed
local heavenlyNum2 = (sexagenaryYear2 - 1) % 10 + 1
local earthlyNum1 = (sexagenaryYear1 - 1) % 12 + 1
local earthlyNum2 = (sexagenaryYear2 - 1) % 12 + 1  
-- Get the data tables for each permutation.
local heavenlyTable1 = heavenlyStems[ heavenlyNum1 ]
local heavenlyTable2 = heavenlyStems[ heavenlyNum2 ]
local earthlyTable1 = earthlyBranches[ earthlyNum1 ]
local earthlyTable2 = earthlyBranches[ earthlyNum2 ]  
-- Work out the continously-numbered year. (See Tibetan calendar#Years with cardinal numbers.)
local year1 = year + 126
local year2 = year + 127
local year1Alt1 = year1 - 381
local year1Alt2 = year1 - 1153
local year2Alt1 = year2 - 381
local year2Alt2 = year2 - 1153  
-- Format any negative numbers.
year1 = formatNegative( tostring( year1 ) )
year2 = formatNegative( tostring( year2 ) )
year1Alt1 = formatNegative( tostring( year1Alt1 ) )
year1Alt2 = formatNegative( tostring( year1Alt2 ) )
year2Alt1 = formatNegative( tostring( year2Alt1 ) )
year2Alt2 = formatNegative( tostring( year2Alt2 ) )  
-- Return all of that data in a (hopefully) reader-friendly format.
tibetan:setYear( string.format(
[=[%s%s年
(%s-%s)
%s or %s or %s
&nbsp;&nbsp;&nbsp;&nbsp;*—&nbsp;to&nbsp;—*
%s%s年
(%s-%s)
%s or %s or %s]=],
heavenlyTable1[ 1 ],
earthlyTable1[ 1 ],
heavenlyTable1[ 2 ],
earthlyTable1[ 2 ],
year1,
year1Alt1,
year1Alt2,
heavenlyTable2[ 1 ],
earthlyTable2[ 1 ],
heavenlyTable2[ 2 ],
earthlyTable2[ 2 ],
year2,
year2Alt1,
year2Alt2
) )  
box:addCalendar( tibetan )  
---
-- Unix time
---  
local unix = calendar:new  
local function getUnixTime( year )
if year < 1970 then return end
local noError, unixTime = pcall( lang.formatDate, lang, 'U', '1 Jan ' .. tostring( year ) )
if not noError or noError and not unixTime then return end
unixTime = tonumber( unixTime )
if unixTime and unixTime >= 0 then
return unixTime - 1
end
end
unix.thisYear = getUnixTime( year )
unix.nextYear = getUnixTime( year + 1 )
if unix.thisYear and unix.nextYear then
unix:setLink( 'Unix time' )
unix:setYear( (unix.thisYear + 1) .. " – " .. unix.nextYear )
end  
box:addCalendar( unix )  
return box:export
end  
---
-- Process arguments from #invoke
---  
local p = {}  
function p.main
-- Process the arguments and pass them to the box-building function.
local args = getArgs
-- Pass year argument with 'year' parameter or without any name but first argument
args.year = args.year or args[1]
return makeCalendarBox( args )
end  
return p