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' },
oci_ins = {'pꞃım', 'ꞅeᵹonꝺ', 'ꞇeꞃç', 'quaꞇꞃen', 'cınquen', 'ꞅeıꞅen'},
eng = {'Prime', 'Secondine', 'Terce', 'Quatrine', 'Quintine', 'Sixtine'},
msc = {'', '','', '', '', ''},
}
local monthnames = {
oci = {'monèm', 'lhinèm', 'tepnèm', 'vounèm', 'nagnèm', 'seunèm', 'monseunèm', 'lhiseunèm', 'tepseunèm', 'vouseunèm', 'naxeunèm', 'selhinèm', 'reunèm'},
oci_ins = {'monèm', 'lhınèm', 'ꞇepnèm', 'ʋolnèm', 'naᵹnèm', 'ꞅeunèm', 'monꞅeunèm', 'lhıꞅeunèm', 'ꞇepꞅeunèm', 'ʋouꞅeunèm', 'naxeunèm', 'ꞅelhınèm', 'ꞃeunèm'},
eng = {'Monem', 'Linem', 'Tepnem', 'Vounem', 'Nanèm', 'Seunem', 'Monseunem', 'Liseunem', 'Tepseunem', 'Vouseunem', 'Naseunem', 'Selinem', 'Reunèm'},
msc = {'', '', '', '', '', '', '',
'', '', '', '', '', ''},
}
local function nahan_num(num)
local placemarker = {[0] ='', '', '', '', '','','','',''}
local values = {[0] = '', '','','','',''}
local out = ''
local place = 0
while 6^place <= num do
local digit = math.floor(num / (6^place)) % 6
if digit == 0 then -- do nothing
elseif digit == 1 and place == 0 then out = out .. values[1]
else
out = out .. placemarker[place] .. values[digit]
end
place = place + 1
end
return out
end
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, ins)
if fem then return tostring(num) .. 'a'
else
if num == 1 then return ins and '1ꞃ' or '1r'
elseif num == 2 then return ins and '2ꝺ' or '2d'
else return tostring(num) .. 'n'
end
end
end,
msc = function(num) return nahan_num(num) .. '<sub></sub>' 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
datestamp = datestamp % 30
local week = math.floor(datestamp / 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)
local y, m, d, w = date_info.year, date_info.month, date_info.day, date_info.week
opts = opts or {}
opts.lang = opts.lang or "eng"
if opts.lang == "eng" and opts.compact then
if m == 13 then return string.format("Cross. %d, R-%d", y, d)
else --[[m ~= 13]] return string.format("Cross. %d, %d-%d’%d", y, m, d, w)
end
elseif opts.lang == "eng" and not opts.compact then
if m == 13 then return string.format("%s of %s, Crossing %d", daynames.eng[d], monthnames.eng[m], y)
else return string.format("%s %s of %s, Crossing %d", ordinal.eng(w), daynames.eng[d], monthnames.eng[m], y)
end
elseif opts.lang == "msc" and opts.compact then
if m == 13 then return string.format(" %s %s", nahan_num(y), nahan_num(d))
else return string.format(" %s %s%s%s", nahan_num(y), nahan_num(m), nahan_num(d), nahan_num(w))
end
elseif opts.lang == "msc" and not opts.compact then
if m ~= 13 then return string.format("%s %s %s %s ", ordinal.msc(w), daynames.msc[d], monthnames.msc[m], ordinal.msc(y))
else return string.format("%s %s %s ", daynames.msc[d], monthnames.msc[m], ordinal.msc(y))
end
elseif opts.lang == "oci" and opts.compact then
if m == 13 then return string.format("Trv. %d, R-%d", y, d)
else return string.format("Trv. %d, %d-%d’%d", y, m, d, w)
end
elseif opts.lang == "oci-ins" and opts.compact then
if m == 13 then return string.format("Ꞇꞃʋ. %d, Ꞃ-%d", y, d)
else return string.format("ꞆꞂƲ. %d, %d-%d’%d", y, m, d, w)
end
elseif opts.lang == "oci" and not opts.compact then
if m == 13 then return string.format("%s de %s, %s de la traversat", daynames.oci[d], monthnames.oci[m], ordinal.oci(y, true))
else return string.format("%s %s de %s, %s de la traversat", ordinal.oci(w, false), daynames.oci[d], monthnames.oci[m], ordinal.oci(y, true))
end
elseif opts.lang == "oci-ins" and not opts.compact then
if m == 13 then return string.format("%s ꝺe %s, %s ꝺe la ꞇꞃaʋeꞃꞅaꞇ", daynames.oci_ins[d], monthnames.oci_ins[m], ordinal.oci(y, true, true))
else return string.format("%s %s ꝺe %s, %s ꝺe la ꞇꞃaʋeꞃꞅaꞇ", ordinal.oci(w, false, true), daynames.oci_ins[d], monthnames.oci_ins[m], ordinal.oci(y, true, true))
end
end
end
return calendar