Module:Calendar/nahan
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Calendar/nahan/doc
local calendar = {}
local equinoxes = require "Module:Calendar/data/equinox_northwards"
local daynames = {
oci = {'prim', 'segond', 'terç', 'quatren', 'cinquen', 'seisen' },
eng = {'Prime', 'Secondine', 'Terce', 'Quatrine', 'Quintine', 'Sixtine'},
}
local monthnames = {
oci = {'monèm', 'lhinèm', 'tepnèm', 'vounèm', 'nagnèm', 'seunèm', 'monseùnem', 'lhiseunèm', 'tepseunèm', 'vouseunèm', 'nagseunèm', 'selhinèm'},
eng = {'Monem', 'Linem', 'Tepnem', 'Vounem', 'Nanèm', 'Seunem', 'Monseunem', 'Liseunem', 'Tepseunem', 'Vouseunem', 'Naseunem', 'Seulinem' }
}
local ordinal = {
eng = function(num)
if num % 10 == 1 and num % 100 ~= 11 then return tostring(num) .. "st"
elseif num % 10 == 2 and num % 100 ~= 12 then return tostring(num) .. "nd"
elseif num % 10 == 3 and num % 100 ~= 13 then return tostring(num) .. "rd"
else return tostring(num) .. "th"
end
end,
oci = function(num, fem)
if fem then return tostring(num) .. 'a'
else
if num == 1 then return '1r'
elseif num == 2 then return '2d'
else return tostring(num) .. 'n'
end
end
end
}
local epoch = -96346 -- year 0
local id_epoch = 0
for i, v in ipairs(equinoxes) do
if v.year == 1707 then -- year 1
id_epoch = i
break
end
end
local function equinox_for(year)
local e = equinoxes[id_epoch + year - 1]
return (e.hour < 6) and e.datestamp - 1 or e.datestamp
end
calendar.from = function(date_info)
if date_info.year < 1 then error "Years before the crossing not supported" end
local datestamp = equinox_for(date_info.year)
datestamp = datestamp + (date_info.month - 1) * 30
datestamp = datestamp + (date_info.week - 1) * 6
datestamp = datestamp + date_info.day - 1
return datestamp
end
calendar.to = function(datestamp)
if datestamp < epoch then error "Years before the crossing not supported" end
local year, nextyear = 0, 1
while equinox_for(nextyear) <= datestamp do
year = nextyear
nextyear = nextyear + 1
end
datestamp = datestamp - equinox_for(year)
local month = math.floor(datestamp / 30) + 1
local week = math.floor ((datestamp % 30) / 6 ) + 1
local day = datestamp % 6 + 1
return{year = year, month = month, week = week, day = day}
end
calendar.to_formatted = function(datestamp, opts)
local date_info = calendar.to(datestamp)
opts = opts or {}
opts.lang = opts.lang or "eng"
if opts.lang == "eng" then
if opts.compact then return string.format("Cross. %d, %d-%d’%d",
date_info.year, date_info.month, date_info.day, date_info.week)
else
return string.format("%s %s of %s, Crossing %s",
ordinal.eng(date_info.week), daynames.eng[date_info.day],
monthnames.eng[date_info.month], date_info.year)
end
elseif opts.lang == "oci" then
if opts.compact then return string.format("Trv. %d, %d-%d’%d",
date_info.year, date_info.month, date_info.day, date_info.week)
else
return string.format("%s %s de %s, %s de la traversat",
ordinal.oci(date_info.week, false), daynames.oci[date_info.day],
monthnames.oci[date_info.month], date_info.year)
end
end
end
return calendar