Ugrás a tartalomhoz

Modul:Is year

A Wikiforrásból

A modult a Modul:Is year/doc lapon tudod dokumentálni

p = {}

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

local function decade_suffix(year)
  local decadeDigit = year:reverse():sub(2,2)
  if decadeDigit == nil then decadeDigit = "" end -- managing year 9 BCE - 9 CE
  local retValue = ""
  if   decadeDigit == "" then 
    retValue = "-ás"
  elseif string.find("14579",decadeDigit) then
    retValue = "-es"
  elseif string.find("02368", decadeDigit) then
    retValue = "-as"
  else
    retValue = nil --should not happen
  end -- switch
  return retValue
end -- decade_suffix  

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*)[%s\.]*$") or ""

  local bcFlag   = (preChrist) and "i.e. " or ""
  local retValue = (mode == "3") and "0" or "FALSE"

  if    mode == "1" then
     retValue = bcFlag..yearnums:gsub("(%d*)(%d)","%1").."0"..decade_suffix(yearnums)
  elseif mode == "2" then
     retValue = bcFlag..math.floor(yearnums/100).."."
  elseif mode == "3" then
     retValue = (yearnums > "") and "1" or "0"
  elseif mode == "4" then
     retValue = (preChrist) and "-1" or "1"
  else
     retValue = bcFlag..yearnums
  end

  return retValue
end

return p