Dungeons & Dragons Lore Wiki

Welcome to the Dungeons & Dragons Lore Wiki, an encyclopedia of official first-party D&D canon from 1974 to the current day.

We need editors! See the editing guidelines for ways to contribute.

READ MORE

Dungeons & Dragons Lore Wiki
No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
-- A script for Greyhawk calendar conversion.
 
-- A script for Greyhawk calendar conversion.
  +
-- Usage: {{#invoke:Date|Convert|year=6106|from=SD|to=CY}}
   
 
local p = {}
 
local cal = {
 
local cal = {
 
["CY"] = { ahead=0, name="Common Year"},
 
["CY"] = { ahead=0, name="Common Year"},
Line 12: Line 14:
 
}
 
}
   
  +
-- Convert between two Greyhawk calendars.
local p = {}
 
  +
-- Usage: {{#invoke:Date|Convert|year=6106|from=SD|to=CY}}
function p.Date ( frame )
 
  +
function p.Convert ( frame )
 
local year = tonumber(frame.args["year"]) or 1
 
local year = tonumber(frame.args["year"]) or 1
 
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"])
Line 28: Line 33:
   
 
return ( outdate .. " [[" .. cal[to]["name"] .. "|" .. to .. "]]" )
 
return ( outdate .. " [[" .. cal[to]["name"] .. "|" .. to .. "]]" )
  +
end
  +
  +
-- Add or subtract a number to a year, accounting for lack of year zero
  +
-- Usage (adding): {{#invoke:Date|Add|year=591|delta=5}}
  +
-- Usage (subtract): {{#invoke:Date|Add|year=591|delta=-1}}
 
function p.Add ( frame )
  +
local year = tonumber(frame.args["year"]) or 1
  +
local delta = tonumber(frame.args["delta"]) or 0
  +
local outdate = year + delta
  +
  +
-- 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
 
end
 
end
   

Latest revision as of 21:27, 17 May 2020

Documentation for this module may be created at Module:Date/doc

-- A script for Greyhawk calendar conversion.
-- Usage: {{#invoke:Date|Convert|year=6106|from=SD|to=CY}}

local p = {}
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"}
}

-- Convert between two Greyhawk calendars.
-- Usage: {{#invoke:Date|Convert|year=6106|from=SD|to=CY}}
function p.Convert ( 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

-- Add or subtract a number to a year, accounting for lack of year zero
-- Usage (adding): {{#invoke:Date|Add|year=591|delta=5}}
-- Usage (subtract): {{#invoke:Date|Add|year=591|delta=-1}}
function p.Add ( frame )
  local year = tonumber(frame.args["year"]) or 1
  local delta = tonumber(frame.args["delta"]) or 0
  local outdate = year + delta

-- 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
end

return p