Module:Keppel date
More actions
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 = {}
-- libraries
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
-- lythryd number to name map
local lythryds = {
'Liliyogh',
'Avonslau',
'Bovvilag',
'Haelaidhe',
'Gildorne',
'Glausonn',
'Ludervinn',
'Auvhlaus',
'Yahataidh',
'Serelakkan',
'Frosma',
'Tegeirukk',
'Intercal'
}
-- time converter
function p.convert(time)
-- offset: 892 years, 79 days (March 20, 892)
local fractionalYear = os.difftime(time, os.time{year = 892, month = 3, day = 20}) / (365.2425 * 86400)
local year = math.floor(fractionalYear)
local yday = fractionalYear % 1 * 389.2541840041
-- lythryd
local lythryd = math.ceil(yday / 32)
local day = math.floor(yday - (lythryd - 1) * 32)
return {
year = year,
lythryd = lythryd,
day = day
}
end
function p.invoke(frame)
local args = getArgs(frame)
local time
if args['year'] and args['month'] and args['day'] then
time = os.time({
year = args['year'],
month = args['month'],
day = args['day']
})
elseif args['time'] then
time = args['time']
elseif args[1] then
time = args[1]
else
time = os.time()
end
return p.convert(time)
end
function p.main(frame)
local args = getArgs(frame)
local result = p.invoke(frame)
local year
if result.year <= 0 then
year = (math.abs(result.year) + 1) .. ' AT'
else
year = result.year .. ' LE'
end
if yesno(args['year_only'] or false) then
return year
elseif yesno(args['month_day_only'] or false) then
return lythryds[result.lythryd] .. ' ' .. result.day
else
return lythryds[result.lythryd] .. ' ' .. result.day .. ', ' .. year
end
end
return p