FANDOM


Line 17: Line 17:
 
local fr = frame.args["from"] or "CY"
 
local fr = frame.args["from"] or "CY"
 
local to = frame.args["to"] or "CY"
 
local to = frame.args["to"] or "CY"
  +
  +
if year == 0 then year = 1 end -- no year zero in Greyhawk calendars
   
 
local outdate = year + (cal[to]["ahead"]-cal[fr]["ahead"])
 
local outdate = year + (cal[to]["ahead"]-cal[fr]["ahead"])

Revision as of 01:09, May 16, 2020

-- A script for Greyhawk calendar conversion.
 
local cal = {
  ["CY"] = { ahead=0,    name="Common Year"},
  ["OL"] = { ahead=804,  name="Olman Lunar"},
  ["OR"] = { ahead=644,  name="Oeridian Record"},
  ["TC"] = { ahead=1407, name="Touv Calendar"},
  ["FT"] = { ahead=2150, name="Flan Tracking"},
  ["BH"] = { ahead=2659, name="Baklunish Hegira"},
  ["OC"] = { ahead=4462, name="Olven Calendar"},
  ["SD"] = { ahead=5515, name="Suloise Dating"}
}
 
local p = {}
function p.Date ( frame )
  local year = tonumber(frame.args["year"]) or 1
  local fr   = frame.args["from"] or "CY"
  local to   = frame.args["to"]   or "CY"
 
  if year == 0 then year = 1 end -- no year zero in Greyhawk calendars
 
  local outdate = year + (cal[to]["ahead"]-cal[fr]["ahead"])
 
-- Special handling of crossing zero line due to lack of year zero
  if year <= 0 and outdate >= 0 then
    outdate = outdate + 1
  elseif year >= 0 and outdate <= 0 then
    outdate = outdate - 1
  end
 
  return ( outdate .. " [[" .. cal[to]["name"] .. "|" .. to .. "]]" )
end
 
return p
Community content is available under CC-BY-SA unless otherwise noted.