Module: Date: Difference between revisions

From A Wiki of Ice and Fire
Jump to: navigation, search
Abjiklam (talk | contribs)
Created page with "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(ye..."
 
Abjiklam (talk | contribs)
No edit summary
Line 41: Line 41:
     local cargs = frame.args
     local cargs = frame.args
      
      
     local y1 = pargs[1] or cargs[1]
     local y1 = tonumber(pargs[1]) or tonumber(cargs[1])
     local suffix = yesno(pargs.suffix, yesno(cargs.suffix, true))
     local suffix = yesno(pargs.suffix, yesno(cargs.suffix, true))
      
      

Revision as of 22:18, 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, yesno(cargs.suffix, true))
    
    return link(y1, suffix)
end

return p