Module:ErraCalendar: Difference between revisions

From Errapedia
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
-- Date table structure
-- Datetime Table Structure
-- "datatype" = "datetime"
-- "year" = int (default 0, range 0-inf)
-- "month" = int (default 1, range 1-9)
-- "date" = int (default 1, range 1-25)
-- "hour" = int (default 0, range 1-23)
-- "minute" = int (default 0, range 0-59)
-- "second" = int (default 0, range 0-59)
--
-- Timedelta Table Structure
-- "datatype = "timedelta"
-- "year" = int
-- "year" = int
-- "month" = int
-- "month" = int
-- "date" = int
-- "date" = int
-- "hour" = int
-- "hour" = int  
-- "minute" = int
-- "minute" = int
-- "second" = int
-- "second" = int
Line 27: Line 37:
   end
   end
   return nil
   return nil
end
function h.ConstructDateTime(inyear, inmonth, indate)
  if inyear == nil then
      inyear = 0
  end
  if inyear < 0 then
      inyear = 0
  end
  if inmonth == nil then
      inmonth = 1
  end
  if inmonth < 1 then
      inmonth = 1
  end
  if inmonth > 9 then
      inmonth = 9
  end
  if indate == nil then
      indate = 1
  end
  if indate < 1 then
      indate = 1
  end
  if indate > 25 then
      indate = 25
  end
  return {datatype="datetime", year=inyear, month=inmonth, date=indate}
end
end

Revision as of 20:15, 9 February 2023

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

-- Datetime Table Structure
-- "datatype" = "datetime"
-- "year" = int (default 0, range 0-inf)
-- "month" = int (default 1, range 1-9)
-- "date" = int (default 1, range 1-25)
-- "hour" = int (default 0, range 1-23)
-- "minute" = int (default 0, range 0-59)
-- "second" = int (default 0, range 0-59)
--
-- Timedelta Table Structure
-- "datatype = "timedelta"
-- "year" = int
-- "month" = int
-- "date" = int
-- "hour" = int 
-- "minute" = int
-- "second" = int

local p = {}
local h = {}

MonthTable = {{name="Een", season="Rise"}, {name="Kar", season="Rise"}, {name="Mir", season="Rise"}, {name="Rort", season="Life"}, {name="Kir", season="Life"}, {name="Sur", season="Life"}, {name="Ith", season="Low"}, {name="Trint", season="Low"}, {name="Sorth", season="Low"}}

function h.GetMonthFromInt( inInt )
   if MonthTable[inInt] == nil then
      return nil
   end
   return MonthTable[inInt]["name"]
end

function h.GetSeasonFromMonthStr( inStr )
   inStr = inStr:lower()
   for _, v in pairs(MonthTable) do
      if v["name"]:lower() == inStr then
         return v["season"]
      end
   end
   return nil
end

function h.ConstructDateTime(inyear, inmonth, indate)
   if inyear == nil then
      inyear = 0
   end
   if inyear < 0 then
      inyear = 0
   end
   if inmonth == nil then
      inmonth = 1
   end
   if inmonth < 1 then
      inmonth = 1
   end
   if inmonth > 9 then
      inmonth = 9
   end
   if indate == nil then
      indate = 1
   end
   if indate < 1 then
      indate = 1
   end
   if indate > 25 then
      indate = 25
   end
   return {datatype="datetime", year=inyear, month=inmonth, date=indate}
end