Модуль:Calendar
Для документации этого модуля может быть создана страница Модуль:Calendar/doc
local p = {}-- Необходимые модули и переменныеlocal getArgs = require('Module:Arguments').getArgslocal yesno = require('Module:Yesno')local mwlang = mw.getContentLanguage()local err = "―" -- NthDay nil resultlocal tCon = table.concat-- 00) Блок многократно используемых списковlocal bool_to_number={ [true]=1, [false]=0 }local monthlang = {"январы","февралы","мартъийы","апрелы","майы","июны","июлы","августы","сентябры","октябры","ноябры","декабры"}local month_to_num = {["январы"]=1,["февралы"]=2,["мартъийы"]=3,["апрелы"]=4,["майы"]=5,["июны"]=6,["июлы"]=7,["августы"]=8,["сентябры"]=9,["октябры"]=10,["ноябры"]=11,["декабры"]=12,["-"]=""}local monthd = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}local params = { {"г", "g"}, {"ю", "j"}}local comment = { '<span style="border-bottom: 1px dotted; cursor: help" title="по юлианскому календарю">','</span>'}-- duplicates:-- AST, BST, CST, ECT, IST, MST, PST, SST, local known_tzs = { ACDT='+10:30', ACST='+09:30', ACT ='+08:00', ADT ='-03:00', AEDT ='+11:00', AEST='+10:00', AFT ='+04:30', AKDT='-08:00', AKST ='-09:00', AMST ='+05:00', AMT ='+04:00', ART ='-03:00', AST ='+03:00', AST ='+04:00', AST ='+03:00', AST ='-04:00', AWDT='+09:00', AWST='+08:00', AZOST='-01:00', AZT ='+04:00', BDT ='+08:00', BIOT='+06:00', BIT ='-12:00', BOT ='-04:00', BRT ='-03:00', BST ='+06:00', BST ='+01:00', BTT ='+06:00', CAT ='+02:00', CCT ='+06:30', CDT ='-05:00', CEDT='+02:00', CEST='+02:00', CET ='+01:00', CHAST='+12:45', CIST='-08:00', CKT ='-10:00', CLST='-03:00', CLT ='-04:00', COST ='-04:00', COT ='-05:00', CST ='-06:00', CST ='+08:00', CVT ='-01:00', CXT ='+07:00', CHST='+10:00', DFT ='+01:00', EAST='-06:00', EAT ='+03:00', ECT ='-04:00', ECT ='-05:00', EDT ='-04:00', EEDT='+03:00', EEST ='+03:00', EET ='+02:00', EST ='-05:00', FJT ='+12:00', FKST='-03:00', FKT ='-04:00', GALT ='-06:00', GET ='+04:00', GFT ='-03:00', GILT='+12:00', GIT ='-09:00', GMT ='+00:00', GST ='-02:00', GYT ='-04:00', HADT='-09:00', HAST ='-10:00', HKT ='+08:00', HMT ='+05:00', HST ='-10:00', IRKT='+08:00', IRST ='+03:30', IST ='+05:30', IST ='+01:00', IST ='+02:00', JST ='+09:00', KRAT ='+07:00', KST ='+09:00', LHST='+10:30', LINT='+14:00', MAGT='+11:00', MDT ='-06:00', MIT ='-09:30', MSD ='+04:00', MSK ='+03:00', MST ='+08:00', MST ='-07:00', MST ='+06:30', MUT ='+04:00', NDT ='-02:30', NFT ='+11:30', NPT ='+05:45', NST ='-03:30', NT ='-03:30', OMST='+06:00', PDT ='-07:00', PETT ='+12:00', PHOT ='+13:00', PKT ='+05:00', PST ='-08:00', PST ='+08:00', RET ='+04:00', SAMT ='+04:00', SAST='+02:00', SBT ='+11:00', SCT ='+04:00', SLT ='+05:30', SST ='-11:00', SST ='+08:00', TAHT='-10:00', THA ='+07:00', UTC ='+00:00', UYST ='-02:00', UYT ='-03:00', VET ='-04:30', VLAT='+10:00', WAT ='+01:00', WEDT ='+01:00', WEST='+01:00', WET ='+00:00', YAKT='+09:00', YEKT ='+05:00', -- US Millitary (for RFC-822) Z='+00:00', A='-01:00', M='-12:00', N='+01:00', Y='+12:00',}local category = {["no_parameters"]="<!--[[Категори:Модуль:Calendar:Страницы без параметров]]-->",["incomplete_parameters"]="<!--[[Категори:Модуль:Calendar:Страницы с неполными или некорректными параметрами]]-->",["without_verification"]="<!--[[Категори:Модуль:Calendar:Страницы без проверки параметров]]-->",["erroneous_parameters"]="<!--[[Категори:Модуль:Calendar:Страницы с ошибочными параметрами]]-->"}-- несколько параметров передаются вместе с кодом ошибки в таблице, один может быть передан простым значениемlocal e = {["start"]="<span class=error>Ошибка: ",["ending"]=".</span>",["no_pattern_match"]="строка «%s» не совпадает с заданными паттернами",["no_valid_date"]="дата «%s» не является корректной",["wrong_jd"]="юлианская дата %s вне диапазона",["no_data"]="нет входящих данных",["too_many_arguments"]="ожидается менее %i аргументов",["too_little_arguments"]="ожидается более %i аргументов",["wrong_calculation"]="даты %s и %s не прошли проверку, %s дней разница",["unknown_param"]="параметр %s неизвестен",["unknown_error"]="неизвестная ошибка",["tech_error"]="ошибка в функции %s",["box_date"]="строка «%s» не является верной датой, пожалуйста, укажите дату в формате ГГГГ-ММ-ДД"--[""]="",}local tzs_names = {"ACDT","ACST","ACT","ADT","AEDT","AEST","AFT","AKDT","AKST","AMST","AMT","ART","AST","AST","AST","AST","AWDT","AWST","AZOST","AZT","BDT","BIOT","BIT","BOT","BRT","BST","BST","BTT","CAT","CCT","CDT","CEDT","CEST","CET","CHAST","CIST","CKT","CLST","CLT","COST","COT","CST","CST","CVT","CXT","CHST","DFT","EAST","EAT","ECT","ECT","EDT","EEDT","EEST","EET","EST","FJT","FKST","FKT","GALT","GET","GFT","GILT","GIT","GMT","GST","GYT","HADT","HAST","HKT","HMT","HST","IRKT","IRST","IST","IST","IST","JST","KRAT","KST","LHST","LINT","MAGT","MDT","MIT","MSD","MSK","MST","MST","MST","MUT","NDT","NFT","NPT","NST","NT","OMST","PDT","PETT","PHOT","PKT","PST","PST","RET","SAMT","SAST","SBT","SCT","SLT","SST","SST","TAHT","THA","UTC","UYST","UYT","VET","VLAT","WAT","WEDT","WEST","WET","YAKT","YEKT","Z","A","M","N","Y","MSK"}local pattern = { -- для распознавания дат, переданных одним строчным параметром{"(-?%d%d%d%d?)[-%.%s/\\](%d%d)[-%.%s/\\](%d%d)", ["order"] = {3,2,1} }, -- yyyy mm dd{"(%d+)[-%.%s/\\](%d+)[-%.%s/\\](%d%d%d%d?)",["order"] = {1,2,3} }, -- dd mm yyyy{"(%d%d)[-%.%s/\\](%d%d%d%d?)", ["order"] = {2,3} }, -- mm yyyy{"(%d%d%d%d?)[-%.%s/\\](%d%d)", ["order"] = {3,2} }, -- yyyy mm{"(%d+)%s(%l+)%s(%d%d%d%d?)", ["order"] = {1,2,3} }, -- d mmm y{"(%l+)%s(%d+),?%s(%d%d%d%d?)", ["order"] = {2,1,3} }, -- mmm d, y{"(%l+)%s(%d%d%d%d?)", ["order"] = {2,3} }, -- mmm y}local time_units = {"year","month","day"} --не используется--[[ local time_units = {"second", "minute", "hour", "day_of_month", "day_of_week", "day_of_year", "week", "month", "year", "year_of_century", "century"} ]]---- напоминание чтобы сделать более точные пересчёты - с часами / расчёт длительностей периодовlocal mnlang = {"ru_G", "ru_N", "en", "de", "fr"}local month_lang = {["ru_G"] = {"января","февраля","марта","апреля","мая","июня","июля","августа","сентября","октября","ноября","декабря"},["ru_N"] = {"январь","февраль","март","апрель","май","июнь","июль","август","сентябрь","октябрь","ноябрь","декабрь"},["en"] = {"january", "february", "march", "april", "may", "june","july", "august", "september", "october", "november", "december"},["de"] = {"januar", "februar", "märz", "april", "mai", "juni","juli", "august", "september", "oktober", "november", "dezember"},["fr"] = {"janvier", "février", "mars", "avril", "mai", "juin","juillet", "août", "septembre", "octobre", "novembre", "décembre"}}-- заполняется автоматическиlocal reverse_month_lang = {}-- вспомогательная функция для обращения таблиц (смена ключей со значениями)local reverse_table = function (strait_table)local reversed_table = {}for k,v in pairs(strait_table) doreversed_table[v] = kendreturn reversed_tableend-- запуск цикла по заполнению обратных таблиц, необходимых для распознавания датlocal filling_months = function (mnlang, month_lang)for i=1, #mnlang doreverse_month_lang[mnlang[i]] = reverse_table(month_lang[mnlang[i]])endend-- 10) Блок общих функцийlocal function trim(str)if not str then return nilelse return str:match'^()%s*$' and '' or str:match'^%s*(.*%S)'endendlocal function purif(str) if str == "" or str == nil then return nil elseif type(tonumber(str)) == "number" then return math.floor(tonumber(str)) else return nil end -- need .5 -- ,5 number format converter?endlocal function is(str)if (not str) or (str == "") then return falseelse return yesno(str,false)endendlocal function init(num)local output = {}for i=1,num dotable.insert(output, {["year"]="", ["month"]="", ["day"]=""})endreturn unpack(output)endlocal function isyear(tbl)if type(tbl) ~= 'table' then return falseelseif not tbl["year"] then return falseelseif type(tbl["year"]) == 'number' then return trueelse return falseendendlocal function inbord(val, down, up)return not (type(up) ~= "number" or type(down) ~= "number" or type(val) ~= "number" or up < down or val < down or val > up)endlocal function shallowcopy(orig) local orig_type = type(orig) local copy if orig_type == 'table' then copy = {} for orig_key, orig_value in pairs(orig) do copy[orig_key] = orig_value end else -- number, string, boolean, etc copy = orig end return copyendlocal inlist = function ( var, list ) local n = #listlocal inlist = falsefor i=1,n doif var == list[i] then inlist = true endend return inlistend-- 20) Блок общих проверочных функций, связанных с датамиlocal function unwarp(tbl)if not tbl then return ""elseif type(tbl) ~= "table" then return tblelseif (tbl.day or tbl.month or tbl.year) thenreturn (tbl.year or "?").."-"..(tbl.month or "?").."-"..(tbl.day or "?")else return (tbl[3] or "?").."-"..(tbl[2] or "?").."-"..(tbl[1] or "?")endendlocal function leap_year(y,jul)if (not y) or (type(y) ~= "number")then return falseelseif (y % 4) ~= 0then return falseelseif not jul and (y % 100 == 0 and y % 400 ~= 0)then return falseelse return trueendend-- функция для вычисления последнего дня месяца для юлианского и григорианского календарейlocal function month_end_day (month,year,is_julian)local month_end_day = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} -- если не задан год, дата 29 февраля считается допустимойif not month or type(month) ~= "number" or month < 1 or month > 12 then return nilelseif month ~= 2 or not year then return month_end_day[month] elseif month == 2 and (year % 4) == 0 and not ((not is_julian) and (year % 100 == 0 and year % 400 ~= 0)) then return 29elseif month == 2 then return 28else return nil -- в случае не целого значения входящих параметров или при иных непредусмотренных событияхendendlocal function isdate ( chain , jul ) -- можно использовать для проверки таблиц с полями day, month, yearif not chain then return falseelseif (not type(chain) == "table")or (not inbord(chain.year,-9999,9999))or (not inbord(chain.month,1,12))or (not inbord(chain.day,1,31))or chain.day > monthd[chain.month]--or chain.year == 0then return falseelseif chain.month == 2 and chain.day == 29 and not leap_year(chain.year,jul)then return falseelse return true end-- check for other calendars needed?endlocal function ispartdate ( chain )if not chain then return falseelseif not (type(chain) == "table") then return falseelseif (inbord(chain.year,-9999,9999)or inbord(chain.month,1,12)or inbord(chain.day,1,31)) then return trueelse return falseend--partial date-- more detailed check for 31.02.0000 needed-- check for other calendars neededend-- from date1 to date2 in one year (beetwen jan-dec, dec-jan needed)local function partdist(date1,date2)local mont, dist = 0, 0local d1d, d1m, d2d, d2m = (date1["day"] or ""), (date1["month"] or ""),(date2["day"] or ""), (date2["month"] or "")if not (inbord(d1d,1,31) and inbord(d2d,1,31)) then return false end-- нужна доп. проверка частичных дат на корректностьif (inbord(d1m,1,12) or inbord(d2m,1,12))and (d1m == "" or d2m == "") thenmont = purif(date1["month"] or date2["month"])d1m, d2m = mont, montend--mw.log("📏 day: " ..d1d .."->"..d2d.." month: ".. d1m.."->"..d2m )if (inbord(d1m,1,12) and d1d <= monthd[d1m])and (inbord(d2m,1,12) and d2d <= monthd[d2m])then if d2m == d1m then dist = d2d - d1delse dist = monthd[d1m] - d1d + d2dendreturn distelse return math.hugeendendlocal function dmdist(d1,d2)local p1,p2 = math.huge,math.hugeif not not partdist(d1,d2) then p1=partdist(d1,d2)endif not not partdist(d2,d1) then p1=partdist(d2,d1)end--if (not p1) or (not p2) then--return (p1 or "") .. (p2 or "")--else--mw.log("d1, d2 = " .. undate(d1) .. ", " .. undate(d2))return math.min(tonumber(partdist(d1,d2)) or math.huge,tonumber(partdist(d2,d1)) or math.huge)--endend-- 30) Блок функций для обработки ввода-вывода датlocal function undate(tbl)if not tbl then return ""else return (tbl.year or "").."-"..(tbl.month or "").."-"..(tbl.day or "")endend-- функция для нормализации значений дат и перевода месяцев в числаlocal function numerize(str) if type(str) == "number" then return math.floor(str)elseif str == "" or str == nil or type(str) ~= "string" thenreturn nil elseif type(tonumber(str)) == "number" then return math.floor(tonumber(str)) else for i=1, #mnlang do if inlist(mw.ustring.lower(str),month_lang[mnlang[i]]) thenreturn reverse_month_lang[mnlang[i]][mw.ustring.lower(str)]end end endend-- функция распознавания даты, переданной одной строкойlocal function parse_date(date_string)if type(date_string) ~= "string" or date_string == "" then return nil endlocal out_date_str = {"","",""}local error_data = {}for i=1, #pattern dolocal result_1, result_2, result_3 = mw.ustring.match(mw.ustring.lower(date_string),pattern[i][1])if (result_1 or "") > "" thenout_date_str[pattern[i].order[1]] = result_1 out_date_str[pattern[i].order[2]] = result_2 if (pattern[i].order[3]) then out_date_str[pattern[i].order[3]] = result_3 end --mw.log("Паттерн " .. i .. ", строка: " .. date_string) breakendendlocal date = {["day"] =numerize(out_date_str[1]),["month"]=numerize(out_date_str[2]),["year"] =numerize(out_date_str[3])}return date --, error_dataend----[[ УСТАРЕЛО ]]----local numstr2date = function(numstr)local format = "Y-m-d"local iso_date = mwlang:formatDate(format,numstr) local y,m,d = string.match(iso_date, "(%d+)-(%d+)-(%d+)")local dateout = {["year"]=purif(y), ["month"]=purif(m), ["day"]=purif(d)} return dateoutend--local numstr2date = function(numstr)--local nums = {}-- local dateout = {}-- for num in string.gmatch(numstr,"(%d+)") do-- table.insert(nums,purif(num))-- end-- if #nums ~= 3 then error("В поле даты вместо трёх чисел с разделителями указано " .. #nums)-- elseif not inbord(nums[2],1,12) then error("Месяц с номером " .. nums[2] .. " не найден")-- elseif not inbord(nums[3],1,31) then-- dateout = {["year"]=nums[3], ["month"]=nums[2], ["day"]=nums[1]}-- elseif not inbord(nums[1],1,31) then-- dateout = {["year"]=nums[1], ["month"]=nums[2], ["day"]=nums[3]}-- elseif inbord(nums[1],1,31) then-- dateout = {["year"]=nums[3], ["month"]=nums[2], ["day"]=nums[1]}-- else--local mwlang = mw.getContentLanguage()--implement mwlang:formatDate(format,datein,true) here-- return error("Не распознано " .. numstr .. " как дата")-- end-- return dateout--endlocal function year2lang(numyear,yearmark,wiki)if not numyear then return "" endif not yearmark then yearmark = "" endlocal output = ""local bcmark = " до н. э."if numyear > 0 thenbcmark = ""else numyear = 1 - numyear endif wiki then --output = tCon({'[[', numyear,' год',bcmark,'|', numyear,']]', " ", yearmark, " ", bcmark})output = tCon({'[[', numyear,' год',bcmark,'|', trim(numyear .. " " .. yearmark .. " " .. bcmark), ']]'})elseoutput = tCon({numyear, " ", yearmark, bcmark})endreturn trim(output)endlocal function day2lang(datein,wikidate,wiki,inner_brt)--if not isdate(wikidate) then wiki = false endif not ispartdate(datein) then return "" endlocal dm_separ, output = "", nilif (not (not datein.day)) and (not (not datein.month)) then dm_separ = " " endif (not datein.month) then datein.month = "" endif (not datein.day) then datein.day = "" endlocal monlan = monthlang[datein.month] or ""if wiki and not inner_brt thenoutput = tCon({"[[", wikidate.day, " ", monthlang[wikidate.month] or "","|", (datein.day or ""), dm_separ, monlan, "]]"})elseif wiki thenoutput = tCon({"[[", wikidate.day, " ", monthlang[wikidate.month] or "","|", (datein.day or ""), dm_separ, monlan})elseoutput = tCon({datein.day, dm_separ, monlan})end return trim(output)endlocal function triple_txt2date(d,m,y)-- добавить (args[1]:match("(%a+)") or "-") для нестандартной записи-- mw.ustring.match((m or ""),"(%a+)")local msg = ""local year = purif((y or "-"):match("(%d+)"))local month = purif(month_to_num[string.lower(mw.ustring.match((m or ""),"(%a+)"))])local day = purif((d or "-"):match("(%d+)"))if not month then msg = category.incomplete_parametersmonth = purif(month_to_num[string.lower(mw.ustring.match((d or ""),"(%a+)") or "-")]) endif (not day) and ((purif(string.match(m or "","(%d+)") or "") or 32) <= (monthd[month] or 31)) then msg = category.incomplete_parametersday = purif(m:match("(%d+)") or "") endif not year then msg = category.incomplete_parametersyear = purif(string.match(m or "","(%d+)") or "") endlocal dateout = {["year"]=year, ["month"]=month, ["day"]=day, ["msg"]=msg}return dateoutendlocal function glue(d1,m1,y1,d2,m2,y2)if (not d1) and (not m1) and (not y1) and (not d2) and (not m2) and (not y2) thenreturn category.incomplete_parameters endlocal gd,gm,gy,jd,jm,jy = (d1 or ""),(m1 or ""),(y1 or ""),(d2 or ""),(m2 or ""),(y2 or "")--mw.log(tCon({gd,gm,gy,jd,jm,jy}))local gm_sep = {" [["," год|","]]"}if (not gy) or (gy == "") then gm_sep = {"","",""} endreturn tCon({comment[1],trim(trim(jd .. " " .. jm) .. " " .. jy ),comment[2]," ([[",trim(gd .. " " .. gm),"]]",gm_sep[1],(gy:match("(%d+)") or ""),gm_sep[2],gy,gm_sep[3],")",category.incomplete_parameters})end-- добавить отображение без годаlocal function double_couple(jdate, gdate, wd, wm, wy, sq_brts, yearmark)local msg = ""msg = (jdate.msg or "") .. (gdate.msg or "")local cd = {}local jd = shallowcopy(jdate)local gd = shallowcopy(gdate)local left = "("local right = ")"if sq_brts then left = "["right = "]"endif (not isdate(jdate,true)) then return error((jdate.day or "") .. "." .. (jdate.month or "") .."." .. (jdate.year or "") .. " неподходящая дата")elseif (not isdate(gdate)) then return error((gdate.day or "") .. "." .. (gdate.month or "") .."." .. (gdate.year or "") .. " неподходящая дата") endif jd.year == gd.year thencd.year = gd.yeargd.year, jd.year = nil, nilendif jd.month == gd.month thencd.month = gd.monthgd.month, jd.month = nil, nilendif (not not cd.month) and wm then return tCon({comment[1] .. trim(day2lang(jd,jdate,false) .. " " .. year2lang(jd.year,yearmark,false)) .. comment[2], trim(left .. day2lang(gd,gdate,wd,wm) .. " " .. year2lang(gd.year,yearmark,wy)) .. right, day2lang(cd,gdate,false) .. "]]", trim(year2lang(cd.year,yearmark,wy)..msg)}, " ")end return tCon({comment[1] .. trim(day2lang(jd,jdate,false) .. " " .. year2lang(jd.year,yearmark,false)) .. comment[2], trim(left .. day2lang(gd,gdate,wd) .. " " .. year2lang(gd.year,yearmark,wy)) .. right, trim(day2lang(cd,gdate,false)), trim(year2lang(cd.year,yearmark,wy)..msg)}, " ")end-- 40) Блок функций для перевода дат с использованием [[Юлианская дата]]local function gri2jd( datein )if not isdate(datein) then return error((datein.day or "") .. "." .. (datein.month or "") .."." .. (datein.year or "") .. " неподходящая дата") end local year = datein.year local month = datein.month local day = datein.day -- jd calculation local a = math.floor((14 - month)/12) local y = year + 4800 - a local m = month + 12*a - 3 local offset = math.floor(y/4) - math.floor(y/100) + math.floor(y/400) - 32045 local jd = day + math.floor((153*m + 2)/5) + 365*y + offset -- jd validation local low, high = -1931076.5, 5373557.49999 if not (low <= jd and jd <= high) then return error((datein.day or "") .. "." .. (datein.month or "") .. "." .. (datein.year or "") .. " выходит за пределы разрешённого диапазона") endreturn jdendlocal function jd2jul( jd )if type(jd) ~= "number" then return error("Промежуточная переменная " .. (jd or "") .. " не является числом") end -- calendar date calculation local c = jd + 32082 local d = math.floor((4*c + 3)/1461) local e = c - math.floor(1461*d/4) local m = math.floor((5*e + 2)/153) local year_out = d - 4800 + math.floor(m/10) local month_out = m + 3 - 12*math.floor(m/10) local day_out = e - math.floor((153*m + 2)/5) + 1 -- output local dateout = {["year"]=year_out, ["month"]=month_out, ["day"]=day_out} return dateoutendlocal function jul2jd( datein )if not isdate(datein,true) then return error((datein.day or "") .. "." .. (datein.month or "") ..".".. (datein.year or "") .. " неподходящая дата") end local year = datein.year local month = datein.month local day = datein.day -- jd calculation local a = math.floor((14 - month)/12) local y = year + 4800 - a local m = month + 12*a - 3 local offset = math.floor(y/4) - 32083 local jd = day + math.floor((153*m + 2)/5) + 365*y + offset -- jd validation local low, high = -1930999.5, 5373484.49999 if not (low <= jd and jd <= high) then return error((datein.day or "") .. "." .. (datein.month or "") .."." .. (datein.year or "") .. " выходит за пределы разрешённого диапазона") endreturn jdendlocal function jd2gri( jd )if type(jd) ~= "number" then return error("Промежуточная переменная " .. (jd or "") .. " не является числом") end -- calendar date calculation local a = jd + 32044 local b = math.floor((4*a + 3) / 146097) local c = a - math.floor(146097*b/4) local d = math.floor((4*c+3)/1461) local e = c - math.floor(1461*d/4) local m = math.floor((5*e+2)/153) local day_out = e - math.floor((153*m+2)/5)+1 local month_out = m + 3 - 12*math.floor(m/10) local year_out = 100*b + d - 4800 + math.floor(m/10) -- output local dateout = {["year"]=year_out, ["month"]=month_out, ["day"]=day_out} return dateoutendlocal function astroyear(num, bc)if not num then return error()elseif type(num) ~= "number" then return error()endif num < 1 then return num endif not bc then return numelse return 1 - numendendlocal function recalc(datein,calend)if inlist(calend,params[1]) then return jd2jul(gri2jd(datein)), datein elseif inlist(calend,params[2]) thenreturn datein, jd2gri(jul2jd(datein)) else error("Параметр " .. (calend or "") .. " не опознан, разрешённые: " .. tCon(params[1]," ") .. " и " .. tCon(params[2]," ")) endend-- 50) Функции для обработки UTClocal function utc(str,margin)local d = 1local dchar = "+"local beginning = "[[UTC"local ending = "]]"local cat = ""local nums = {}local hmarg, timedec = 0, 0local mmarg = "00"local output = ""-- checking type of inputif not margin then margin = 0elseif type(tonumber(margin)) ~= 'number' thenoutput = "Can't shift by " .. marginerror(output)endif type(str) ~= 'string' thenerror("Нет входящей строки")elseif str:byte(1) == 43 thenelseif inbord(str:byte(1),48,57) then cat = "[[Категория:Википедия:Ошибка в часовом поясе НП]]"elseif str:byte(1) == 45 or string.sub(str,1,3) == "−" or string.sub(str,1,1)=="-" then d = -1elseerror(string.char(str:byte(1)) .. " недопустимый первый символ")end-- parsing inputfor num in string.gmatch(str,"(%d+)") do table.insert(nums,purif(num)) endif #nums > 2 then error("Ожидается всего 2 числа, а не " .. #nums)elseif #nums == 0 then error("Необходимо что-то ввести")elseif #nums == 1 thenif inbord(nums[1],0,14) then timedec = d*nums[1] + marginelse error("Только часы от -14 до 14") endelseif #nums == 2 thenif not inbord(nums[1],0,14) then error("Только часы от -14 до 14")elseif not inbord(nums[2],0,59) then error("Минуты только от 0 до 59")elsetimedec = d*(nums[1] + nums[2]/60) + marginendendif tonumber(timedec) == purif(timedec) then hmarg = timedecelselocal h, m = math.modf(math.abs(timedec))hmarg = hmmarg = math.floor(m*60)endif timedec == 0 thendchar = "±"elseif timedec > 0 thenelseif timedec < 0 thendchar = "−"end-- outputoutput = beginning .. dchar .. math.abs(hmarg) .. ":" .. string.format("%02d",mmarg) .. ending .. catreturn outputend-- 60) Блок функций ввода-выводаfunction p.NthDay( frame ) local args = getArgs(frame, { frameOnly = true }) local num, wday, mont, yea, format = purif(args[1]), purif(args[2]), purif(args[3]), purif(args[4]), args[5]if not format then format = "%d.%m.%y" end if not inbord(num,-5,5) then return error("The number must be between -5 and 5") elseif num == 0 then return error("The number must not be zero") end if not inbord(wday,0,6) then return error("The day of the week must be between 0 and 6") end if not inbord(mont,1,12) then return error("The month must be between 1 and 12") end if not inbord(yea,0,9999) then return error("Wrong year number") end if inbord(num,1,5) then local m_start = os.time{year=yea, month=mont, day=1, hour=0} local m_wds = tonumber(os.date("%w", m_start)) local start_shift = ( (num - bool_to_number[wday >= m_wds]) * 7 - (m_wds - wday) ) * 24 * 60 * 60 local tim = m_start + start_shift if tonumber(os.date("%m", tim)) == mont then return (os.date(format, tim)) else return (err) end elseif inbord(num,-5,-1) then local m_end = os.time{year = yea, month = mont + 1, day = 1, hour = 0} - 24 * 60 * 60 local m_wde = tonumber(os.date("%w", m_end)) local end_shift = ((math.abs(num + 1) + bool_to_number[wday > m_wde]) * 7 + (m_wde - wday)) * 24 * 60 * 60 local tim = m_end - end_shift if tonumber(os.date("%m", tim)) == mont then return (os.date(format, tim)) else return (err) end endend-- =p.ToIso(mw.getCurrentFrame():newChild{title="smth",args={"12 декабря 2020"}})-- =p.ToIso(mw.getCurrentFrame():newChild{title="smth",args={"1.2.1602"}})-- =p.ToIso(mw.getCurrentFrame():newChild{title="smth",args={"12.12.2021"}})-- =p.ToIso(mw.getCurrentFrame():newChild{title="smth",args={"2021.12.12"}})function p.ToIso( frame ) local args = getArgs(frame, { frameOnly = true }) local datein = args[1] -- инициализация, заполнение обратных таблиц, копирование параметровfilling_months(mnlang, month_lang) -- парсинг входящей даты по шаблону local date = parse_date(datein) if not (type(date.year) == 'number') then return ("Wrong year: " .. unwarp(date)) end if not (1 <= date.month and date.month <= 12) then return ("Wrong month: " .. unwarp(date)) end if not date.day or not (1 <= date.day and date.day <= month_end_day(date.month,date.year)) then return ("Wrong day: " .. unwarp(date)) end local timedate = os.time{year=date.year, month=date.month, day=date.day} local date = os.date("%Y-%m-%d", timedate) return dateend-- =p.BoxDate(mw.getCurrentFrame():newChild{title="smth",args={"12 декабря 2020"}})-- =p.BoxDate(mw.getCurrentFrame():newChild{title="smth",args={"1.2.1602"}})-- =p.BoxDate(mw.getCurrentFrame():newChild{title="smth",args={"декабрь 2020"}})-- =p.BoxDate(mw.getCurrentFrame():newChild{title="smth",args={"12-2020"}})-- =p.BoxDate(mw.getCurrentFrame():newChild{title="smth",args={"12.12.2021"}})-- =p.BoxDate(mw.getCurrentFrame():newChild{title="smth",args={"2021.12.12"}})-- =p.BoxDate(mw.getCurrentFrame():newChild{title="smth",args={"2021.11"}})-- =p.BoxDate(mw.getCurrentFrame():newChild{title="smth",args={"11.2021"}})function p.BoxDate( frame ) local args = getArgs(frame, { frameOnly = true }) local txtDateIn, strFormat = args[1], args[2] local txtDateOut, date, status = p.bxDate(txtDateIn, strFormat, params)if status.brk thenreturn error(status.errorText)elsereturn txtDateOutendendfunction p.bxDate( txtDateIn , strFormat, params ) -- к отладкеlocal txtDateOut, date, status = "", {}, {brk = false, errorCat = "", errorText = ""}strFormat = strFormat or "j xg Y"-- заглушка - таблица параметров на будущееparams = params or {}if not txtDateIn then status.errorText = e.no_datastatus.errorCat = category.no_parametersstatus.brk = trueelse-- заполнение служебных таблицfilling_months(mnlang, month_lang)endif not status.brk then-- парсинг входящей даты по шаблонуdate = parse_date(txtDateIn) -- заменить сообщения об ошибках на списочные if not (date.year and type(date.year) == 'number') then status.errorText = string.format(e.box_date,txtDateIn) status.errorCat = category.incomplete_parameters status.brk = true end if not inbord(date.month,1,12) then status.errorText = string.format(e.box_date,txtDateIn) status.errorCat = category.incomplete_parameters status.brk = true end if not date.day and string.find(strFormat,"[dDjlNwzW]") then strFormat = trim(string.gsub(string.gsub(strFormat,"xg","F"),"[dDjlNwzW]","")) elseif not date.day then elseif not inbord(date.day,1,month_end_day(date.month,date.year)) then status.errorText = string.format(e.box_date,txtDateIn) status.errorCat = category.incomplete_parameters status.brk = true endendif not status.brk thentxtDateOut = mwlang:formatDate(strFormat,tCon({date.year,date.month,date.day},"-"),true)end return txtDateOut, date, statusendfunction p.ToDate( frame ) -- возможно неиспользуемая local args = getArgs(frame, { frameOnly = true }) local mwlang = mw.getContentLanguage() local datein = args[1] local format = "j xg Y" if not string.match(datein, "%p") then return datein elseif not args[2] then else format = args[2] end return mwlang:formatDate(format,datein,true)end-- =p.unitime(mw.getCurrentFrame():newChild{title="smth",args={"−1:30","1"}})function p.unitime( frame ) local args = getArgs(frame, { frameOnly = true }) local DST = 0 if not args[2] then else DST = 1 end local utcin = "" local input = args[1] if not input then return "" end if inlist(input:upper(),tzs_names) then utcin = known_tzs[input:upper()] elseif (string.sub(input:upper(),1,3) == 'UTC') and (string.len(input) < 10) then utcin = string.sub(input,4) else if string.sub(input,1,1) == '[' or string.sub(input,1,1) == '{' or string.sub(input,1,1):upper() == 'U' or string.sub(input,1,1):upper() == 'M' then return input -- elseif not string.find(string.upper(string.sub(input,1,1)),"[\65-\90]") or-- not string.find(string.upper(string.sub(input,1,1)),"[\192-\223]") then-- return input else utcin = input end end-- elseif string.sub(input,1,3) ~= "−" then utcin = input-- or not (not input:find("[А-я]")) при наличии в строке юникода не работает local output = "" if DST == 0 then output = utc(utcin) else output = utc(utcin) .. ", [[сæрдыгон рæстæг|сæрды]] " .. utc(utcin,DST) end return outputend-- УСТАРЕЛО-- =p.OldDate(mw.getCurrentFrame():newChild{title="smth",args={"20.02.2020","ю",["bc"]="1",["wd"]="1",["wy"]="1",["sq_brts"]="1",["yearmark"]="г."}})function p.OldDate( frame ) local args = getArgs(frame, { frameOnly = true }) if not args[1] then return err end local gdate, jdate = {}, {} local strin = args[1] local cal = args[2]:lower() or "г" local bc = is(args["bc"]) local wd = is(args["wd"]) local wm = is(args["wm"]) local wy = is(args["wy"]) if not wd then wm = false end local sq_brts = is(args["sq_brts"]) local yearmark = "года" if yesno(args["yearmark"]) then elseif yesno(args["yearmark"]) == false then yearmark = "" else yearmark = trim(args["yearmark"]) or "года" end-- local infocard = is(args["infocard"])-- local catName = args["catName"] or false local datein = numstr2date(strin) datein.year = astroyear(datein.year, bc) jdate, gdate = recalc(datein,cal)return double_couple(jdate, gdate, wd, wm, wy, sq_brts, yearmark)end-- =p.NewDate(mw.getCurrentFrame():newChild{title="Salt",args={"2020-02-20"}})-- =p.NewDate(mw.getCurrentFrame():newChild{title="smth",args={"20.02.2020","ю",["bc"]="1",["wd"]="1",["wy"]="1",["sq_brts"]="1",["yearmark"]="г."}})-- =p.NewDate(mw.getCurrentFrame():newChild{title="smth",args={"20.02.2020",["bc"]="0",["wd"]="1",["wy"]="1",["sq_brts"]="0",["yearmark"]=""}})function p.NewDate( frame ) local args = getArgs(frame, { frameOnly = true }) if not args[1] then return err endlocal strin = args[1] local year, month, day if not not strin:match( "(-?%d%d%d%d%d)-(%d%d)-(%d%d)" ) then year, month, day = strin:match( "(-?%d%d%d%d%d)-(%d%d)-(%d%d)" ) elseif not not strin:match( "(-?%d+)-(%d+)-(%d+)" ) then year, month, day = strin:match( "(-?%d+)-(%d+)-(%d+)" ) elseif not not strin:match( "(%d%d)%.(%d%d)%.(-?%d%d%d%d%d)" ) then day, month, year = strin:match( "(%d%d)%.(%d%d)%.(-?%d%d%d%d%d)" ) elseif not not strin:match( "(%d+)%.(%d+)%.(-?%d+)" ) then day, month, year = strin:match( "(%d+)%.(%d+)%.(-?%d+)" )endif not year then return error(args[1] .. " не подходит под форматы yyyy-mm-dd или dd.mm.yyyy")endlocal cal = "г"if (not args[2]) or (args[2] == "") then cal = "г"else cal = args[2]:lower() endlocal bc,wd,wm,wy,sq_brts = is(args["bc"]),is(args["wd"]),is(args["wd"]) and is(args["wm"]),is(args["wy"]),is(args["sq_brts"])year = astroyear(purif(year),bc)local datein = {["year"]=purif(year), ["month"]=purif(month), ["day"]=purif(day)}local jdate, gdate = recalc(datein,cal) local yearmark = "года" local ym = args["yearmark"] or "" if yesno(ym) then elseif yesno(ym) == false then yearmark = "" else if not not ym:match("(%d+)") then error("Цифры в обозначении года: " .. ym) else yearmark = trim(ym) or "года" end endreturn double_couple(jdate, gdate, wd, wm, wy, sq_brts, yearmark)end-- =p.Test(mw.getCurrentFrame():newChild{title="smth",args={}})-- =p.Test(mw.getCurrentFrame():newChild{title="smth",args={"3","июня",nil,"21","мая"}})-- =p.Test(mw.getCurrentFrame():newChild{title="smth",args={"28 августа","","1916 года","15"}})-- =p.Test(mw.getCurrentFrame():newChild{title="smth",args={"3","июня","1900","21","мая"}})-- =p.Test(mw.getCurrentFrame():newChild{title="smth",args={"6","июня","1889 год","25","мая"}}) -- =p.Test(mw.getCurrentFrame():newChild{title="smth",args={"28","ноября","1917","15"}})-- =p.Test(mw.getCurrentFrame():newChild{title="smth",args={"28 августа","nil","1916 года","15"}}) -- =p.Test(mw.getCurrentFrame():newChild{title="smth",args={"4","января","1915","22","декабря","1914 года"}}) -- {{OldStyleDate|день (НС)|месяц (НС)|год (НС)|день (СС)|месяц (СС)|год (СС)}}function p.Test( frame )local args = getArgs(frame, { frameOnly = true })-- необходима проверка и замена nil на " "--[[mw.log((args[1] or "") .. " " .. (args[2] or "") .. " " .. (args[3] or "") .. " " .. (args[4] or "") .. " " .. (args[5] or "") .. " " .. (args[6] or "")) ]]--local ingdate = triple_txt2date(args[1],args[2],args[3])local injdate = triple_txt2date(args[4],args[5],args[6])local j1date, g1date, j2date, g2date = init(4)mw.log("ingdate-".. (undate(ingdate) or ""))mw.log("injdate-".. (undate(injdate) or ""))local bc,wd,wm,wy,sq_brts,ny = is(args["bc"]),is(args["wd"]),is(args["wd"]) and is(args["wm"]),is(args["wy"]),is(args["sq_brts"]),is(args["ny"])-- подавление формата для локальных тестов local wd, wm, wy = true, true, true local yearmark = "года" local ym = args["yearmark"] or ((mw.ustring.match((args[3] or ""),"(%a+)") or mw.ustring.match((args[6] or ""),"(%a+)")) or "") -- mw.log("ym " .. ym) if yesno(ym) then elseif yesno(ym) == false then yearmark = "" else if not not ym:match("(%d+)") then error("Цифры в обозначении года: " .. ym) else yearmark = trim(ym) or "года" end end if isdate(ingdate) or isdate(injdate) thenif isdate(ingdate) thenj1date, g1date = recalc(ingdate,"g")ingdate["full"] = trueendif isdate(injdate) thenj2date, g2date = recalc(injdate,"j")injdate["full"] = trueendif ispartdate(ingdate) and ispartdate(injdate) thenmw.log("📏 " .. dmdist(ingdate,injdate))mw.log("📏 " .. dmdist(j1date,g1date))mw.log("📏 " .. dmdist(j2date,g2date))mw.log("📏 " .. dmdist(ingdate,g1date))mw.log("📏 " .. dmdist(injdate,j2date))endendif ny then if isyear(j1date) thenelse j1date["year"] = "" endif isyear(j2date) == nil thenelse j2date["year"] = "" endif isyear(g1date) == nil thenelse g1date["year"] = "" endif isyear(g2date) == nil thenelse g2date["year"] = "" endendif (isdate(j1date) and isdate(g1date) and isdate(j2date) and isdate(g2date)) thenif ((j1date.year == j2date.year)and (j1date.month == j2date.month)and (j1date.day == j2date.day)) thenreturn double_couple(j1date, g1date, wd, wm, wy, sq_brts, yearmark)else mw.log("📏 " .. (tostring(dmdist(ingdate,injdate)) or ""))return glue(args[1],args[2],args[3],args[4],args[5],args[6]) -- категория (предположительная разница в днях) и частичный выводendelseif isdate(j1date) and isdate(g1date) thenreturn double_couple(j1date, g1date, wd, wm, wy, sq_brts, yearmark) -- категория плюс частичная проверкаelseif isdate(j2date) and isdate(g2date) thenreturn double_couple(j2date, g2date, wd, wm, wy, sq_brts, yearmark) -- категория плюс частичная проверкаelseif (ispartdate(ingdate) and ispartdate(injdate)) thenmw.log("ingdate ".. (undate(ingdate) or ""))mw.log("injdate ".. (undate(injdate) or ""))mw.log("j1date " .. (undate(j1date ) or ""))mw.log("j2date " .. (undate(j2date ) or ""))mw.log("g1date " .. (undate(g1date ) or ""))mw.log("g2date " .. (undate(g2date ) or ""))mw.log("📏 " .. (tostring(partdist(ingdate,injdate)) or "").. " — " .. (tostring(partdist(injdate,ingdate)) or ""))return glue(args[1],args[2],args[3],args[4],args[5],args[6]) -- частичный или полный вывод, категорияelse mw.log("ingdate ".. (undate(ingdate) or ""))mw.log("injdate ".. (undate(injdate) or ""))mw.log("j1date " .. (undate(j1date ) or ""))mw.log("j2date " .. (undate(j2date ) or ""))mw.log("g1date " .. (undate(g1date ) or ""))mw.log("g2date " .. (undate(g2date ) or ""))return err .. category.incomplete_parametersendendreturn p
🔥 Top keywords: Сæйраг фарсДыккаг дунеон хæстВикипеди:НыхасВикипеди:БæрнВикипеди:Хъазуатон куыстУæрæсейы Федерацийы социалон картæВикипеди:АфыстСæрмагонд:ФæстагИвдтытæÆххуыс:МидисВикипедиБангладешVk.comВикипеди:Ног хабæрттæСæрмагонд:АгурынИрон æвзагКатегори:ÆппæтЧехиУчастник:JamesofurУæрæсеХетæгкаты КъостаГуырдзыстонХуссар ИрыстонУкраинæАрубæПалестинæЭнарейтæКъуыдайраг ныхасыздæхтХуызæг:Ромайнаг æвзæгтæФайл:Flag of Ukraine.svgИспаниАмерикæйы Иугонд ШтаттæЦыргъобауКатегори:1956-æм азы чи райгуырдис, уыдон1200-æм азЕвропæйы Цæдис800-æм азСтыр БританиШиизмСомих