Module: Date
From A Wiki of Ice and Fire
Documentation for this module may be created at Module:Date/doc
local yesno = require('Module:Yesno')
local p = {}
local function is_empty(s)
return s == nil or s == ''
end
function p.link(year, suffix)
local s, name, page
if year > 0 then
s = tostring(year)
name = suffix and (s .. " ᴀᴄ") or s
page = mw.title.makeTitle(0, s .. " AC")
if not page.exists then
page = mw.title.makeTitle(
0,
"Years after Aegon's Conquest",
"Year " .. s .. " After the Conquest"
)
end
elseif year < 0 then
s = tostring(math.abs(year))
name = suffix and (s .. " ʙᴄ") or s
page = mw.title.makeTitle(0, s .. " BC")
if not page.exists then
page = mw.title.makeTitle(
0,
"Years before Aegon's Conquest",
"Year " .. s .. " Before the Conquest"
)
end
end
return "[[" .. page.fullText .. "|" .. name .. "]]"
end
function p.nolink(year, suffix)
local s = tostring(year)
if year > 0 then
return suffix and (s .. " ᴀᴄ") or s
elseif year < 0 then
s = tostring(math.abs(year))
return suffix and (s .. " ʙᴄ") or s
end
end
function p.main(frame)
local pargs = frame:getParent().args
local cargs = frame.args
local y1 = tonumber(pargs[1]) or tonumber(cargs[1])
local y2 = tonumber(pargs[2]) or tonumber(cargs[2])
local suffix = yesno(pargs.suffix)
if suffix == nil then suffix = yesno(cargs.suffix) end
if suffix == nil then suffix = true end
if y1 == nil then
local text = pargs[1] or cargs[1]
return "[[Years after Aegon's Conquest|" .. text .. " ᴀᴄ]]"
elseif y2 == nil then
return p.link(y1, suffix)
elseif (y1 > 0) == (y2 > 0) then
return p.link(y1, false) .. "–" .. p.link(y2, true)
else
return p.link(y1, true) .. " – " .. p.link(y2, true)
end
end
return p