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 |
||
| (2 intermediate revisions by the same user not shown) | |||
| 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 // If I find anyone vandalising this I'll personally violate your behind | |||
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 | ||
| Line 28: | Line 38: | ||
local moon = (diffDays % 7) + 1 | local moon = (diffDays % 7) + 1 | ||
return | return era .. "E, Dawn " .. dawn | ||
end | end | ||
return p | return p | ||
Latest revision as of 11:08, 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 // If I find anyone vandalising this I'll personally violate your behind
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 era .. "E, Dawn " .. dawn
end
return p