Module:ArcaneCalendar: Difference between revisions
Jump to navigation
Jump to search
(Created page with "local p = {} function p.convertDate(frame) local args = frame.args local year = tonumber(args.year) local month = tonumber(args.month) local day = tonumber(args.day) -- Define start dates of each era (adjust as needed) local era_start = { [1] = { year = 2023, month = 8, day = 16 }, [2] = { year = 2024, month = 7, day = 21 } } local era = 2 -- Default to the latest era for e, start in pairs(era_start) do if (...") |
No edit summary |
||
Line 3: | Line 3: | ||
function p.convertDate(frame) | function p.convertDate(frame) | ||
local args = frame.args | local args = frame.args | ||
local year = tonumber(args.year) | local year = tonumber(args.year) or 0 | ||
local month = tonumber(args.month) | local month = tonumber(args.month) or 0 | ||
local day = tonumber(args.day) | local day = tonumber(args.day) or 0 | ||
-- Define start dates of each era | -- Validate input | ||
if year == 0 or month == 0 or day == 0 then | |||
return "Invalid date input. Please provide year, month, and day." | |||
end | |||
-- Define start dates of each era | |||
local era_start = { | local era_start = { | ||
[1] = { year = 2023, month = 8, day = 16 }, | [1] = { year = 2023, month = 8, day = 16 }, | ||
Line 13: | Line 18: | ||
} | } | ||
local era = | local era = 1 -- Default to 1st Era | ||
for e, start in pairs(era_start) do | for e, start in pairs(era_start) do | ||
if (year > start.year) or (year == start.year and month > start.month) or (year == start.year and month == start.month and day >= start.day) then | if (year > start.year) or (year == start.year and month > start.month) or (year == start.year and month == start.month and day >= start.day) then | ||
Line 23: | Line 28: | ||
local startDate = os.time({ year = start.year, month = start.month, day = start.day }) | local startDate = os.time({ year = start.year, month = start.month, day = start.day }) | ||
local inputDate = os.time({ year = year, month = month, day = day }) | local inputDate = os.time({ year = year, month = month, day = day }) | ||
-- Check if inputDate is valid | |||
if not inputDate then | |||
return "Invalid date." | |||
end | |||
local diffDays = math.floor((inputDate - startDate) / 86400) -- Convert seconds to days | local diffDays = math.floor((inputDate - startDate) / 86400) -- Convert seconds to days |
Revision as of 10:56, 1 February 2025
Documentation for this module may be created at Module:ArcaneCalendar/doc
local p = {} function p.convertDate(frame) local args = frame.args local year = tonumber(args.year) or 0 local month = tonumber(args.month) or 0 local day = tonumber(args.day) or 0 -- Validate input if year == 0 or month == 0 or day == 0 then return "Invalid date input. Please provide year, month, and day." end -- Define start dates of each era local era_start = { [1] = { year = 2023, month = 8, day = 16 }, [2] = { year = 2024, month = 7, day = 21 } } local era = 1 -- Default to 1st Era for e, start in pairs(era_start) do if (year > start.year) or (year == start.year and month > start.month) or (year == start.year and month == start.month and day >= start.day) then era = e end end local start = era_start[era] local startDate = os.time({ year = start.year, month = start.month, day = start.day }) local inputDate = os.time({ year = year, month = month, day = day }) -- Check if inputDate is valid if not inputDate then return "Invalid date." end local diffDays = math.floor((inputDate - startDate) / 86400) -- Convert seconds to days local dawn = math.floor(diffDays / 7) + 1 local moon = (diffDays % 7) + 1 return dawn .. "th Dawn of the " .. era .. "nd Era, " .. moon .. "th Moon" end return p