Difference between revisions of "Module: Date"
From A Wiki of Ice and Fire
Line 94: | Line 94: | ||
function p._format(d) | function p._format(d) | ||
− | return tonumber(d) and p. | + | return tonumber(d) and p._main{d} or d |
end | end | ||
return p | return p |
Revision as of 14:16, 14 September 2018
Documentation for this module may be created at Module:Date/doc
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local p = {}
local year_articles = { -- When an article is created for a specific year, add it to the list. Don't forget the negative sign for BC !
[120] = true,
[129] = true,
[130] = true,
[131] = true,
[196] = true,
[209] = true,
[212] = true,
[280] = true,
[281] = true,
[282] = true,
[283] = true,
[284] = true,
[285] = true,
[289] = true,
[290] = true,
[297] = true,
[298] = true,
[299] = true,
[300] = true,
}
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
if year_articles[year] then
page = mw.title.makeTitle(0, s .. " AC")
else
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
if year_articles[year] then
page = mw.title.makeTitle(0, s .. " BC")
else
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 args = getArgs(frame)
return p._main(args)
end
function p._main(args)
local y1 = tonumber(args[1])
local y2 = tonumber(args[2])
local suffix = yesno(args.suffix)
if suffix == nil then suffix = true end
if y1 == nil then
local text = args[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
function p._format(d)
return tonumber(d) and p._main{d} or d
end
return p