Module:Keppel date: Difference between revisions
More actions
Tesinormed (talk | contribs) Undo revision 38516 by Tesinormed (talk) |
Tesinormed (talk | contribs) No edit summary |
||
| Line 64: | Line 64: | ||
local result = p.convertDate(date) |
local result = p.convertDate(date) |
||
return result.lythryd .. result.lythrydDay .. ', ' .. result.year .. ' (yday ' .. result.daynumraw .. ')' |
return result.lythryd .. ' ' .. result.lythrydDay .. ', ' .. result.year .. ' (yday ' .. result.daynumraw .. ')' |
||
end |
end |
||
Revision as of 18:46, March 4, 2025
Converts the current (or provided) date to a Keppel date. Used by Template:Keppel date.
Formula
\begin{aligned} y_\oplus &= \text{Earth year} \\ d_\oplus &= \text{Earth day of year (fractional)} \\ d_{\oplus_\text{max}}(y_\oplus) &= \begin{cases} 366 & (y_\oplus = 0 \pmod{4} \text{ and } y_\oplus \neq 0 \pmod{100}) \text{ or } y_\oplus = 0 \pmod{400} \\ 365 & \text{otherwise} \end{cases} \\ \text{offset}(y_\oplus) &= d_{\oplus_\text{max}}(y_\oplus) - 287 \\ d_{\text{K}_\text{max}}(y_\text{K}) &= \begin{cases} 391 & y_\text{K} = 65 \pmod{239} \text{ and } y_\text{K} = 2 \pmod{4} \\ 390 & y_\text{K} = 65 \pmod{239} \text{ or } y_\text{K} = 2 \pmod{4} \\ 389 & \text{otherwise} \end{cases} \\ y_\text{K}(y_\oplus) &= y_\oplus - 892 \\ y_\text{K} &= \begin{cases} y_\text{K}(y_\oplus) & d_\oplus - \text{offset}(y_\oplus) \geq \frac{d_{\oplus_\text{max}}(y_\oplus)}{d_{\text{K}_\text{max}}(y_\text{K}(y_\oplus))} \\ y_\text{K}(y_\oplus) - 1 & d_\oplus - \text{offset}(y_\oplus) < \frac{d_{\oplus_\text{max}}(y_\oplus)}{d_{\text{K}_\text{max}}(y_\text{K}(y_\oplus))} \end{cases} \\ d_\text{K} &= (\frac{d_\oplus - \text{offset}(y_\oplus)}{d_{\oplus_\text{max}}(y_\oplus)} \times d_{\text{K}_\text{max}}(y_\text{K}) - 1) \bmod{d_{\text{K}_\text{max}}(y_\text{K})} + 1 \\ L_\text{K} &= \lfloor \frac{d_\text{K} - 1}{32} \rfloor + 1 \\ d_{\text{K}_L} &= \lfloor (d_\text{K} - 1) \bmod{32} \rfloor + 1 \end{aligned}
local p = {}
local function isEarthLeapYear(year)
return (year % 400 == 0) or (year % 100 ~= 0 and year % 4 == 0)
end
local function isKeppelLeapYear1(year)
return year % 4 == 2
end
local function isKeppelLeapYear2(year)
return year % 239 == 65
end
local lythryd = {
'Liliyogh',
'Avonslau',
'Bovvilag',
'Haelaidhe',
'Gildorne',
'Glausonn',
'Ludervinn',
'Auvhlaus',
'Yahataidh',
'Serelakkan',
'Frosma',
'Tegeirukk',
'Intercal'
}
function p.convertDate(date)
-- maximum amount of days in a year (Earth)
local ydayMaxEarth = isEarthLeapYear(date.year) and 366 or 365
-- maximum amount of days in a year (Keppel)
local ydayMax = 389
if isEarthLeapYear(date.year) then ydayMax = ydayMax + 1 end
if isKeppelLeapYear1(date.year) then ydayMax = ydayMax + 1 end
if isKeppelLeapYear2(date.year) then ydayMax = ydayMax + 1 end
-- rollover offset
local rolloverOffset = isEarthLeapYear(date.year) and 79 or 78
-- Keppel year and year day
local year = date.year - 892
local yday = ((ydayMax * (date.yday - rolloverOffset)) / ydayMaxEarth) % ydayMax
local daynumraw = math.floor(yday)
local lythrydNumber = math.floor(yday / 32)
local lythrydDay = math.floor(yday - lythrydNumber * 32)
return {
year = year,
daynumraw = daynumraw,
lythrydNumber = lythrydNumber,
lythryd = lythryd[lythrydNumber],
lythrydDay = lythrydDay
}
end
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame)
local time = args['time'] or os.time()
local date = os.date('!*t', time)
local result = p.convertDate(date)
return result.lythryd .. ' ' .. result.lythrydDay .. ', ' .. result.year .. ' (yday ' .. result.daynumraw .. ')'
end
return p