FANDOM


local p = {}
 
local function link(year)
  local res = ""
  if year == "?" then
    return "?"
  else
    year = tonumber(year)
  end
  if year < 0 then
    year = -year
    res = "[[征服前纪事#征服前" .. year .. "年|" .. year .. "BC]]"
  elseif year <= 1 then
    res = "[[伊耿历纪事#伊耿历元年|" .. year .. "AC]]"
  else 
    res = "[[伊耿历纪事#伊耿历" .. year .. "年|" .. year .. "AC]]"
  end
  return res
end
 
local function smartLink(year)
  local res = ""
  if year == "?" then
    return "?"
  else
    year = tonumber(year)
  end
  if year < 0 then
    year = -year
    if mw.title.makeTitle("",year.."BC").id==0 then
      res = "[[征服前纪事#征服前" .. year .. "年|" .. year .. "BC]]"
    else
      res = "[["..year.."BC]]"
    end
  elseif year <= 1 then
    if mw.title.makeTitle("",year.."AC").id==0 then
      res = "[[伊耿历纪事#伊耿历元年|" .. year .. "AC]]"
    else
      res = "[["..year.."AC]]"
    end
  else 
    if mw.title.makeTitle("",year.."AC").id==0 then
      res = "[[伊耿历纪事#伊耿历" .. year .. "年|" .. year .. "AC]]"
    else
      res = "[["..year.."AC]]"
    end  
  end
  return res
end
 
function p.date(frame)
  local res, res2 = ""
  local ok = false
  local one = frame.args[1]
  local two = frame.args[2]
  if one == "" and two == "" then
    res = "[[伊耿历纪事|?AC]]"
    return res
  end
  if one ~= "" then
    ok, res = pcall(smartLink, one)
    if not ok then
      res = link(one)
    end 
  else
    res = "?"
  end
  if two ~= "" then
    ok, res2 = pcall(smartLink, two)
    if not ok then
        res2 = link(two)
    end
    res = res .. " - " .. res2
  end
  return res
end
 
return p
除了特别提示,社区内容遵循CC-BY-SA 授权许可。