Modul:Is century
Megjelenés
A függvény az {{ez egy évszázad}} sablont valósítja meg
p = {}
local function trim(s)
return s:match'^%s*(.*%S)' or ''
end
function p.check(params)
local args = require( 'Modul:Arguments' ).getArgs(params)
local yeartext = args[1] or ""
local mode = args[2] or ""
local preChrist = false
if yeartext:sub(1,4):upper() == "I.E." then
preChrist = true
yearspart = trim(yeartext:sub(5))
elseif yeartext:sub(1,5):upper() == "KR.E." then
preChrist = true
yearspart = trim(yeartext:sub(6))
elseif yeartext:sub(1,1) == '-' then
preChrist = true
yearspart = trim(yeartext:sub(2))
elseif yeartext:sub(1,5):upper() == "I.SZ." then
yearspart = trim(yeartext:sub(6))
elseif yeartext:sub(1,5):upper() == "KR.U." then
yearspart = trim(yeartext:sub(6))
else
yearspart = yeartext
end
local yearnums = yearspart:match("(%d*\.)% század") or ""
local bcFlag = (preChrist) and "i.e. " or ""
local retValue = (mode == "3") and "0" or "FALSE"
if mode == "1" then
retValue = (preChrist) and -tonumber(yearnums)+1 or tonumber(yearnums) -- az i.e. 1. század a 0. sorszámú
elseif mode == "2" then
retValue = (preChrist) and -yearnums or yearnums
elseif mode == "3" then
retValue = (yearnums > "") and "1" or "0"
else
retValue = bcFlag..yearnums
end
return retValue
end
return p