Difference between revisions of "Module: Date"

From A Wiki of Ice and Fire
Jump to: navigation, search
Line 43: Line 43:
 
     local y1 = tonumber(pargs[1]) or tonumber(cargs[1])
 
     local y1 = tonumber(pargs[1]) or tonumber(cargs[1])
 
     local suffix = yesno(pargs.suffix)
 
     local suffix = yesno(pargs.suffix)
     if suffix == nil then suffix = yesno(cargs.suffix, true) end
+
     if suffix == nil then suffix = yesno(cargs.suffix) end
 +
    if suffix == nil then suffix = true end
 
      
 
      
 
     return link(y1, suffix)
 
     return link(y1, suffix)

Revision as of 22:26, 29 August 2018

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

local function link(year, suffix)
    local s = tostring(year)
    local name, page
    if year > 0 then
        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
        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
    elseif year < 0 then
    end
    return "[[" .. page.fullText .. "|" .. name .. "]]"
end

function p.main(frame)
    local pargs = frame:getParent().args
    local cargs = frame.args
    
    local y1 = tonumber(pargs[1]) or tonumber(cargs[1])
    local suffix = yesno(pargs.suffix)
    if suffix == nil then suffix = yesno(cargs.suffix) end
    if suffix == nil then suffix = true end
    
    return link(y1, suffix)
end

return p