Module:lnk-date: Difference between revisions
Jump to navigation
Jump to search
TheNightAvl (talk | contribs) mNo edit summary |
TheNightAvl (talk | contribs) mNo edit summary |
||
Line 128: | Line 128: | ||
return data["rad"]["days"][laenk_date.wday] .. ", " .. data["rad"]["date"][laenk_date.day] .. " " .. data["rad"]["months"][laenk_date.month] .. " nyentusk " .. laenk_date.year .. "șk" | return data["rad"]["days"][laenk_date.wday] .. ", " .. data["rad"]["date"][laenk_date.day] .. " " .. data["rad"]["months"][laenk_date.month] .. " nyentusk " .. laenk_date.year .. "șk" | ||
else -- traditional format | else -- traditional format | ||
return mw.ustring.gsub(data["rad"]["week"][laenk_date.mweek] .. " " .. data["rad"]["days"][laenk_date.wday], "(a a)", "ag a") .. " " .. data["rad"]["months"][laenk_date.month] .. " nyentusk " .. laenk_date.year .. "șk" | local temp_first = "" | ||
if laenk_date.mweek == 1 then temp_first = " helișe" end | |||
return mw.ustring.gsub(data["rad"]["week"][laenk_date.mweek] .. " " .. data["rad"]["days"][laenk_date.wday] .. temp_first, "(a a)", "ag a") .. " " .. data["rad"]["months"][laenk_date.month] .. " nyentusk " .. laenk_date.year .. "șk" | |||
end | end | ||
end | end |
Revision as of 00:14, 18 February 2024
See {{date}}
. All language data can be found at Module:lnk-date/data.
local export = {}
local getArgs = require('Module:Arguments').getArgs
local data = mw.loadData("Module:lnk-date/data")
local m_links = require("Module:links")
local m_languages = require("Module:languages")
local date_today = os.date("*t")
local year_offset = 0 -- <- a positive offset will add to the current year
function get_laenk_date(d_value, m_value, y_value)
local greg_date = {
["day"] = d_value,
["month"] = m_value,
["year"] = y_value,
}
local laenk_date = {
["day"] = 0,
["month"] = 0,
["year"] = greg_date.year + year_offset,
["yday"] = 0,
["week"] = 0,
["mweek"] = 0,
["wday"] = 0,
["is_leapyear"] = false,
}
local last_laenk_ny = {
["day"] = 20,
["month"] = 3,
["year"] = greg_date.year - 1,
}
if os.date("*t", os.time(greg_date)).yday > 79 or (os.date("*t", os.time(greg_date)).yday == 79 and os.date("*t", os.time({["day"] = 31, ["month"] = 12, ["year"] = greg_date.year})).yday == 365) then
laenk_date.year = laenk_date.year + 1
last_laenk_ny.year = last_laenk_ny.year + 1
end
if os.date("*t", os.time({["day"] = 31, ["month"] = 12, ["year"] = laenk_date.year})).yday == 366 then
laenk_date.is_leapyear = true
end
laenk_date.yday = math.floor((os.difftime(os.time(greg_date), os.time(last_laenk_ny)) / (24 * 60 * 60)) + 0.5) -- sometimes it returns 5.98... instead of 6, hence +0.5
laenk_date.month = math.floor(laenk_date.yday / 30) + 1
laenk_date.day = (laenk_date.yday % 30) + 1
laenk_date.week = math.floor(laenk_date.yday / 6) + 1
laenk_date.mweek = math.floor(laenk_date.yday / 6) + 1 - (laenk_date.month-1) * 5
laenk_date.wday = (laenk_date.yday % 6) + 1
return laenk_date
end
function export.show(frame)
local args = getArgs(frame)
local greg_year = date_today.year
local greg_month = date_today.month
local greg_day = date_today.day
local parameters = {}
local p = 1
local greg_wday = os.date("*t", os.time({["day"] = greg_day, ["month"] = greg_month, ["year"] = greg_year})).wday
if args[1] and args[2] and args[3] then
if mw.ustring.find(args[1], "([0-9]+)") and mw.ustring.find(args[2], "([0-9]+)") and mw.ustring.find(args[3], "([0-9]+)") then
greg_year = tonumber(args[3])
greg_month = tonumber(args[2])
greg_day = tonumber(args[1])
p = 4
end
end
-- process all parameters --
while args[p] do
parameters[args[p]] = true
p = p + 1
end
local laenk_date = get_laenk_date(greg_day, greg_month, greg_year)
if parameters["greg"] then
if parameters["word"] then
if parameters["rad"] then
return data["rad"]["greg"]["days"][greg_wday] .. ", " .. data["rad"]["date"][greg_day] .. " " .. data["rad"]["greg"]["months"][greg_month] .. " nyentusk " .. greg_year .. "șk"
else
return data["eng"]["days"][greg_wday] .. ", " .. greg_day .. " " .. data["eng"]["months"][greg_month] .. " " .. greg_year
end
else
return greg_day .. "/" .. greg_month .. "/" .. greg_year .. " (" .. greg_wday .. ")"
end
--[[ The possible variables you can call are as follows:
laenk_date.year
laenk_date.month
laenk_date.day
laenk_date.week (calls the week number within the whole year)
laenk_date.mweek (calls the week number within the month as values 1–5)
laenk_date.wday (calls the day of the week as values 1–6)
These will always return a number. You can use this number to index your language data using data["lfv"]["months"][laenk_date.month], for example, or just use it on its own when formatting dates with numbers.
★ EXAMPLE FORMATTING ★
elseif parameters["lfv"] then
if parameters["word"] then -- word format
if laenk_date.month == 13 then -- 13th month date format
else -- if months 1-12
end
else -- number format
-- PUT YOUR CODE TO FORMAT THE DATE HERE
end
You can use any word as a parameter. Just set up an if parameters[" ... "] then … with a word or phrase you want to use as a calling argument and it will be recognised. For example, Rad has a "mod" parameter, which is only mentioned in the if statements below, and then I can call it in the {{date}} template.
]]
-- Radestrian formatting
elseif parameters["rad"] then
if parameters["word"] then -- word format
if laenk_date.month == 13 then -- 13th month date format doesn't differ between modern and traditional
if laenk_date.is_leapyear == false and laenk_date.day == 5 then
laenk_date.day = 6
end
return data["rad"]["days-13"][laenk_date.day] .. " " .. data["rad"]["months"][13] .. " nyentusk " .. laenk_date.year .. "șk"
else -- if months 1-12
if parameters["mod"] then -- modern format
return data["rad"]["days"][laenk_date.wday] .. ", " .. data["rad"]["date"][laenk_date.day] .. " " .. data["rad"]["months"][laenk_date.month] .. " nyentusk " .. laenk_date.year .. "șk"
else -- traditional format
local temp_first = ""
if laenk_date.mweek == 1 then temp_first = " helișe" end
return mw.ustring.gsub(data["rad"]["week"][laenk_date.mweek] .. " " .. data["rad"]["days"][laenk_date.wday] .. temp_first, "(a a)", "ag a") .. " " .. data["rad"]["months"][laenk_date.month] .. " nyentusk " .. laenk_date.year .. "șk"
end
end
else -- date format
if parameters["mod"] then -- modern format
return laenk_date.day .. "/" .. laenk_date.month .. "/" .. laenk_date.year
else -- traditional format
if laenk_date.month == 13 then
return laenk_date.wday .. "/" .. laenk_date.month .. "/" .. laenk_date.year
else
return laenk_date.mweek .. "·" .. laenk_date.wday .. "/" .. laenk_date.month .. "/" .. laenk_date.year
end
end
end
-- end of Radestrian formatting
-- standard DD/MM/YYYY setting
else
if parameters["word"] then
if laenk_date.month == 13 then
return data["eng"]["months-lnk"][13] .. " " .. data["eng"]["days-lnk"][laenk_date.day] .. " " .. laenk_date.year
else
return data["eng"]["week"][laenk_date.mweek] .. " " .. data["eng"]["days-lnk"][laenk_date.wday] .. " of " .. data["eng"]["months-lnk"][laenk_date.month] .. " " .. laenk_date.year
end
else
return laenk_date.day .. "/" .. laenk_date.month .. "/" .. laenk_date.year .. " (" .. laenk_date.wday .. ")"
end
end
end
-- CALENDAR FOR MAIN PAGE
function export.calendar()
local time_data = get_laenk_date(date_today.day, date_today.month, date_today.year)
--local time_data = get_laenk_date(15, 3, 2023)
local highlight = "bgcolor=\"#f5ffcc\" style=\"outline: solid 1px\""
mw.logObject(time_data)
local return_table = {}
local function add(term) table.insert(return_table, term) end
local function link(lang, word)
return m_links.full_link{
term = word,
language = m_languages.get_by_code(lang)
}
end
local function highlighter(condition, pre, post)
if condition then
add(pre .. " " .. highlight .. post)
else
add(pre .. post)
end
end
local function grey(pre, post)
add(pre .. " style=\"color:gray\"" .. post)
end
add("<table class=\"floatright\" style=\"border:1px solid #AAA; padding-left: 10px; padding-top: 1px; padding-bottom: 5px; padding-right: 10px; border-spacing: 7px; width: 40%; text-align: center\">")
add("<th colspan=2><small>LAENKEAN YEAR " .. time_data.year .. "</small></th>")
add("<tr><th colspan=2>")
add("<table class=\"floatright\" style=\"border:1px solid #AAA; padding: 0px; border-spacing: 10px; width: 100%; text-align: center;\"><tr>")
highlighter(time_data.month == 1, "<th width=16.6%", "><small>MARCH<br>" .. link("lfv", "kwilliehda") .. "<br>" .. link("rad", "vanints") .. "</small></th>")
highlighter(time_data.month == 2, "<th width=16.6%", "><small>APRIL<br>" .. link("lfv", "ǧiernilda") .. "<br>" .. link("rad", "hrelners") .. "</small></th>")
highlighter(time_data.month == 3, "<th width=16.6%", "><small>MAY<br>" .. link("lfv", "mialtehda") .. "<br>" .. link("rad", "gjembraus") .. "</small></th>")
highlighter(time_data.month == 4, "<th width=16.6%", "><small>JUNE<br>" .. link("lfv", "rimpêñilda") .. "<br>" .. link("rad", "dvuoþers") .. "</small></th>")
highlighter(time_data.month == 5, "<th width=16.6%", "><small>JULY<br>" .. link("lfv", "hestiehda") .. "<br>" .. link("rad", "hraers") .. "</small></th>")
highlighter(time_data.month == 6, "<th width=16.6%", "><small>AUGUST<br>" .. link("lfv", "buhda") .. "<br>" .. link("rad", "sfvocía") .. "</small></th>")
add("</tr><tr>")
highlighter(time_data.month == 7, "<th width=16.6%", "><small>SEPTEMBER<br>" .. link("lfv", "šambuhda") .. "<br>" .. link("rad", "alua") .. "</small></th>")
highlighter(time_data.month == 8, "<th width=16.6%", "><small>OCTOBER<br>" .. link("lfv", "þahtaida") .. "<br>" .. link("rad", "irgotua") .. "</small></th>")
highlighter(time_data.month == 9, "<th width=16.6%", "><small>NOVEMBER<br>" .. link("lfv", "fihda") .. "<br>" .. link("rad", "cynuers") .. "</small></th>")
highlighter(time_data.month == 10, "<th width=16.6%", "><small>DECEMBER<br>" .. link("lfv", "sumpêñilda") .. "<br>" .. link("rad", "háșers") .. "</small></th>")
highlighter(time_data.month == 11, "<th width=16.6%", "><small>JANUARY<br>" .. link("lfv", "malluida") .. "<br>" .. link("rad", "mvaþers") .. "</small></th>")
highlighter(time_data.month == 12, "<th width=16.6%", "><small>FEBRUARY<br>" .. link("lfv", "ǧiôhda") .. "<br>" .. link("rad", "dzevans") .. "</small></th>")
add("</tr></table></th></tr><tr><td>")
add("<table class=\"floatright\" style=\"border:1px solid #AAA; padding: 0px; border-spacing: 10px; width: 100%; text-align: center;\"><tr>")
highlighter(time_data.month ~= 13 and time_data.wday == 1, "<th width=16.6%", "><small>PRINDINE<br>" .. link("lfv", "assiolku") .. "<br>" .. link("rad", "varyga") .. "</small></th>")
highlighter(time_data.month ~= 13 and time_data.wday == 2, "<th width=16.6%", "><small>SECUNDINE<br>" .. link("lfv", "spadiolku") .. "<br>" .. link("rad", "atía") .. "</small></th>")
highlighter(time_data.month ~= 13 and time_data.wday == 3, "<th width=16.6%", "><small>TERCIDINE<br>" .. link("lfv", "lêjolku") .. "<br>" .. link("rad", "liría") .. "</small></th>")
highlighter(time_data.month ~= 13 and time_data.wday == 4, "<th width=16.6%", "><small>QUARTINE<br>" .. link("lfv", "majoku") .. "<br>" .. link("rad", "asedua") .. "</small></th>")
highlighter(time_data.month ~= 13 and time_data.wday == 5, "<th width=16.6%", "><small>QUINTINE<br>" .. link("lfv", "skipôda") .. "<br>" .. link("rad", "laía") .. "</small></th>")
highlighter(time_data.month ~= 13 and time_data.wday == 6, "<th width=16.6%", "><small>SEXTINE<br>" .. link("lfv", "þuôkôda") .. "<br>" .. link("rad", "valygdras") .. "</small></th>")
add("</tr>")
for i = 1, 30 do
if i % 6 == 1 then
add("<tr>")
end
highlighter(time_data.month ~= 13 and time_data.day == i, "<td", ">" .. i .. "</td>")
if i % 6 == 0 then
add("</tr>")
end
end
add("</table></td><td>")
add("<table class=\"floatright\" style=\"border:1px solid #AAA; padding: 0px; border-spacing: 10px; width: 90%; text-align: center\">")
add("<th><small>WEEK<br>" .. link("lfv", "najost") .. "<br>" .. link("rad", "areans") .. "</small></th>")
for i = 1, 5 do
highlighter(time_data.month ~= 13 and time_data.mweek == i, "<tr><td", ">" .. i .. "</td></tr>")
end
add("</table></td></tr><tr><td colspan=2>")
add("<table class=\"floatright\" style=\"border:1px solid #AAA; padding: 0px; border-spacing: 10px; width: 100%; text-align: center\">")
highlighter(time_data.month == 13, "<tr><th", "><center><small>FERIAE<br>" .. link("lfv", "hlwêhda") .. "<br>" .. link("rad", "dzestasans") .. "</small></center></th></tr>")
add("</table></td></tr><tr><td colspan=2>")
add("<table class=\"floatright\" style=\"border:1px solid #AAA; padding: 0px; border-spacing: 10px; width: 100%; text-align: center\">")
add("<tr><th></th>")
if time_data.is_leapyear then
highlighter(time_data.month == 13 and time_data.day == 1, "<th width=16.6%", "><small>SEXTA</small></th>")
highlighter(time_data.month == 13 and time_data.day == 2, "<th width=16.6%", "><small>QUINTA</small></th>")
highlighter(time_data.month == 13 and time_data.day == 3, "<th width=16.6%", "><small>QUARTA</small></th>")
highlighter(time_data.month == 13 and time_data.day == 4, "<th width=16.6%", "><small>TERTIA</small></th>")
highlighter(time_data.month == 13 and time_data.day == 5, "<th width=16.6%", "><small>SECUNDA</small></th>")
highlighter(time_data.month == 13 and time_data.day == 6, "<th width=16.6%", "><small>PRIMA</small></th>")
else
grey("<th width=16.6%", "><small>SEXTA</small></th>")
highlighter(time_data.month == 13 and time_data.day == 1, "<th width=16.6%", "><small>QUINTA</small></th>")
highlighter(time_data.month == 13 and time_data.day == 2, "<th width=16.6%", "><small>QUARTA</small></th>")
highlighter(time_data.month == 13 and time_data.day == 3, "<th width=16.6%", "><small>TERTIA</small></th>")
highlighter(time_data.month == 13 and time_data.day == 4, "<th width=16.6%", "><small>SECUNDA</small></th>")
highlighter(time_data.month == 13 and time_data.day == 5, "<th width=16.6%", "><small>PRIMA</small></th>")
end
add("</tr><tr>")
add("<th>[[File:LaefevianFlag.png|36px]]</th>")
if time_data.is_leapyear then
highlighter(time_data.month == 13 and time_data.day == 1, "<td", ">6</td>")
highlighter(time_data.month == 13 and time_data.day == 2, "<td", ">5</td>")
highlighter(time_data.month == 13 and time_data.day == 3, "<td", ">4</td>")
highlighter(time_data.month == 13 and time_data.day == 4, "<td", ">3</td>")
highlighter(time_data.month == 13 and time_data.day == 5, "<td", ">2</td>")
highlighter(time_data.month == 13 and time_data.day == 6, "<td", ">1</td>")
else
grey("<td", ">6</td>")
highlighter(time_data.month == 13 and time_data.day == 1, "<td", ">5</td>")
highlighter(time_data.month == 13 and time_data.day == 2, "<td", ">4</td>")
highlighter(time_data.month == 13 and time_data.day == 3, "<td", ">3</td>")
highlighter(time_data.month == 13 and time_data.day == 4, "<td", ">2</td>")
highlighter(time_data.month == 13 and time_data.day == 5, "<td", ">1</td>")
end
add("</tr>")
-- Radestrian 13th month
add("<tr><th></th>")
highlighter(time_data.month == 13 and time_data.day == 1, "<th", "><small>PRIMA<br>" .. link("rad", "asía") .. "</small></th>")
highlighter(time_data.month == 13 and time_data.day == 2, "<th", "><small>SECUNDA<br>" .. link("rad", "atía") .. "</small></th>")
highlighter(time_data.month == 13 and time_data.day == 3, "<th", "><small>TERTIA<br>" .. link("rad", "liría") .. "</small></th>")
highlighter(time_data.month == 13 and time_data.day == 4, "<th", "><small>QUARTA<br>" .. link("rad", "aía") .. "</small></th>")
if time_data.is_leapyear then
highlighter(time_data.month == 13 and time_data.day == 5, "<th", "><small>QUINTA<br>" .. link("rad", "vaía") .. "</small></th>")
highlighter(time_data.month == 13 and time_data.day == 6, "<th", "><small>ULTIMA<br>" .. link("rad", "valygdras") .. "</small></th>")
else
grey("<th", "><small>QUINTA<br>(" .. link("rad", "vaía") .. ")</small></th>")
highlighter(time_data.month == 13 and time_data.day == 5, "<th", "><small>ULTIMA<br>" .. link("rad", "valygdras") .. "</small></th>")
end
add("</tr><tr>")
add("<th>[[File:RadestrianFlag.png|36px]]</th>")
highlighter(time_data.month == 13 and time_data.day == 1, "<td", ">1</td>")
highlighter(time_data.month == 13 and time_data.day == 2, "<td", ">2</td>")
highlighter(time_data.month == 13 and time_data.day == 3, "<td", ">3</td>")
highlighter(time_data.month == 13 and time_data.day == 4, "<td", ">4</td>")
if time_data.is_leapyear then
highlighter(time_data.month == 13 and time_data.day == 5, "<td", ">5</td>")
highlighter(time_data.month == 13 and time_data.day == 6, "<td", ">6</td>")
else
grey("<td", ">—</td>")
highlighter(time_data.month == 13 and time_data.day == 5, "<td", ">5</td>")
end
add("</tr></table></td></tr></table>")
return table.concat(return_table, mw.ustring.char(10))
end
return export
--[[
Debug console test string:
=p.show(mw.getCurrentFrame():newChild{title="whatever",args={}})
]]