Az ez_egy_évtized sablon által hívott segédfüggvény


p = {}

local function trim(s)
  return s:match'^%s*(.*%S)' or ''
end

function p.check(params)
  local argModule   = require( 'Modul:Arguments' )
  local args        = argModule.getArgs(params)
  local yeartext    = args[1]
  local mode        = args[2]
  local preChrist   = false
  local retValue    = (mode == "3") and "0" or "FALSE"
  local yearsnum    = 0
  local bindVowel   = ""
  local decadeDigit = ""

  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

  yearnums,bindVowel = mw.ustring.match(yearspart,"(%d*0)%-([aeá])s")

  local bcFlag = (preChrist) and "i.e. " or ""

  if yearnums ~=nil then  
    decadeDigit =  yearnums:reverse():sub(2,2)

    if decadeDigit == nil then decadeDigit = "" end -- a 0-ás eset kezelése
         
    local vocalHarmony_ok =    string.find("14579",decadeDigit) and bindVowel == "e"
                            or string.find("02368", decadeDigit) and bindVowel == "a"
                            or decadeDigit == "" and bindVowel == "á"

    if vocalHarmony_ok then
       if    mode == "1" then
           if preChrist then 
             retValue = -tonumber(yearnums)/10
           else
             retValue = tonumber(yearnums)/10
           end  
       elseif mode == "2" then
           if preChrist then 
              retValue = -yearnums
           else
              retValue = yearnums
           end
       elseif mode == "3" then
           retValue = 1
       else
           retValue = bcFlag..yearnums
       end
    end -- vovalHarmony   
  else
    yearnums = ""
  end -- yearnums
  return retValue
end

return p