59 lines
1.7 KiB
Text
59 lines
1.7 KiB
Text
local seasons = {"Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath"}
|
|
local weekdays = {"Sweetmorn", "Boomtime", "Pungenday", "Prickle-Prickle", "Setting Orange"}
|
|
local apostles = {"Mungday", "Mojoday", "Syaday", "Zaraday", "Maladay"}
|
|
local holidays = {"Chaoflux", "Discoflux", "Confuflux", "Bureflux", "Afflux"}
|
|
|
|
local function parse(date)
|
|
local y = tonumber(date:sub(1, 4))
|
|
local m = tonumber(date:sub(6, 7))
|
|
local d = tonumber(date:sub(9, 10))
|
|
return y, m, d
|
|
end
|
|
|
|
local function is_leap_year(y) return (y % 4 == 0 and y % 100 != 0) or y % 400 == 0 end
|
|
|
|
local function discordian(date)
|
|
local y, m, d = parse(date)
|
|
local yold = $" in the YOLD {y + 1166}."
|
|
local t = os.time({year = y, month = m, day = d})
|
|
local doy = tonumber(os.date("%j", t))
|
|
if is_leap_year(y) then
|
|
if doy == 60 then return "St. Tib's Day" .. yold end
|
|
if doy > 60 then doy -= 1 end
|
|
end
|
|
doy -= 1
|
|
local season_day = doy % 73 + 1
|
|
local season_nr = doy // 73 + 1
|
|
local weekday_nr = doy % 5 + 1
|
|
local holyday = ""
|
|
if season_day == 5 then holyday = $" Celebrate {apostles[season_nr]}!" end
|
|
if season_day == 50 then holyday = $" Celebrate {holidays[season_nr]}!" end
|
|
local season = seasons[season_nr]
|
|
local dow = weekdays[weekday_nr]
|
|
return string.format("%s, day %s of %s%s%s", dow, season_day, season, yold, holyday)
|
|
end
|
|
|
|
local dates = {
|
|
"2010-01-01",
|
|
"2010-01-05",
|
|
"2011-02-19",
|
|
"2012-02-28",
|
|
"2012-02-29",
|
|
"2012-03-01",
|
|
"2013-03-19",
|
|
"2014-05-03",
|
|
"2015-05-31",
|
|
"2016-06-22",
|
|
"2016-07-15",
|
|
"2017-08-12",
|
|
"2018-09-19",
|
|
"2018-09-26",
|
|
"2019-10-24",
|
|
"2020-12-08",
|
|
"2020-12-31"
|
|
}
|
|
|
|
for dates as date do
|
|
local dt = discordian(date)
|
|
print($"{date} = {dt}")
|
|
end
|