Изменения
обновление
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local yesno = require('Module:Yesno')
local lang = mw.getContentLanguage()
local mwlang = mw.getContentLanguage()
local err = "―" -- NthDay nil result
local err = "―" -- NthDay nil result
local tCon = table.concat
-- 00) Блок многократно используемых списков
-- 00) Блок многократно используемых списков
local params = { {"г", "g"}, {"ю", "j"}}
local params = { {"г", "g"}, {"ю", "j"}}
local comment = { '<span style="border-bottom: 1px dotted; cursor: help" title="по юлианскому календарю">','</span>'}
local comment = { '<span style="border-bottom: 1px dotted; cursor: help" title="по юлианскому календарю">','</span>'}
local known_tzs = {
local known_tzs = {
}
}
local category = {
local category = {
["no_parameters"]=
"<!--[[Категория:Модуль:Calendar:Страницы без параметров]]-->",
["incomplete_parameters"]=
["incomplete_parameters"]=
"<!--[[Категория:Модуль:Calendar:Страницы с неполными или некорректными параметрами]]-->",
"<!--[[Категория:Модуль:Calendar:Страницы с неполными или некорректными параметрами]]-->",
["ending"]=".</span>",
["ending"]=".</span>",
["no_pattern_match"]="строка «%s» не совпадает с заданными паттернами",
["no_pattern_match"]="строка «%s» не совпадает с заданными паттернами",
["no_valid_date"]="дата «%s·%s·%s» не является корректной",
["no_valid_date"]="дата «%s» не является корректной",
["wrong_jd"]="юлианская дата %s вне диапазона",
["wrong_jd"]="юлианская дата %s вне диапазона",
["no data"]="нет входящих данных",
["too_many_arguments"]="ожидается менее %i аргументов",
["too_many_arguments"]="ожидается менее %i аргументов",
["too_little_arguments"]="ожидается более %i аргументов",
["too_little_arguments"]="ожидается более %i аргументов",
["wrong_calculation"]="даты %s и %s не прошли проверку, %s дней разница",
["wrong_calculation"]="даты %s и %s не прошли проверку, %s дней разница",
["unknown_calendar"]="параметр календаря %s неизвестен",
["unknown_param"]="параметр %s неизвестен",
["unknown_error"]="неизвестная ошибка",
["unknown_error"]="неизвестная ошибка",
["tech_error"]="ошибка в функции %s",
["tech_error"]="ошибка в функции %s",
-- [""]="",
-- [""]="",
}
}
elseif type(tbl) ~= "table" then return tbl
elseif type(tbl) ~= "table" then return tbl
elseif (tbl.day or tbl.month or tbl.year) then
elseif (tbl.day or tbl.month or tbl.year) then
return "Y"..(tbl.year or "?").."•M"..(tbl.month or "?").."•D"..(tbl.day or "?")
return (tbl.year or "?").."-"..(tbl.month or "?").."-"..(tbl.day or "?")
else return (tbl[3] or "?").."-"..(tbl[2] or "?").."-"..(tbl[1] or "?")
else return (tbl[3] or "?").."-"..(tbl[2] or "?").."-"..(tbl[1] or "?")
end
end
----[[ УСТАРЕЛО ]]----
----[[ УСТАРЕЛО ]]----
local numstr2date = function(numstr)
local numstr2date = function(numstr)
local format = "Y-m-d"
local format = "Y-m-d"
local iso_date = lang:formatDate(format,numstr)
local iso_date = mwlang:formatDate(format,numstr)
local y,m,d = string.match(iso_date, "(%d+)-(%d+)-(%d+)")
local y,m,d = string.match(iso_date, "(%d+)-(%d+)-(%d+)")
local dateout = {["year"]=purif(y), ["month"]=purif(m), ["day"]=purif(d)}
local dateout = {["year"]=purif(y), ["month"]=purif(m), ["day"]=purif(d)}
-- dateout = {["year"]=nums[3], ["month"]=nums[2], ["day"]=nums[1]}
-- dateout = {["year"]=nums[3], ["month"]=nums[2], ["day"]=nums[1]}
-- else
-- else
-- local lang = mw.getContentLanguage()
-- local mwlang = mw.getContentLanguage()
-- implement lang:formatDate(format,datein,true) here
-- implement mwlang:formatDate(format,datein,true) here
-- return error("Не распознано " .. numstr .. " как дата")
-- return error("Не распознано " .. numstr .. " как дата")
-- end
-- end
local day = purif((d or "-"):match("(%d+)"))
local day = purif((d or "-"):match("(%d+)"))
if not month then
if not month then
msg = category["params"]
msg = category.incomplete_parameters
month = purif(month_to_num[string.lower(mw.ustring.match((d or ""),"(%a+)") or "-")])
month = purif(month_to_num[string.lower(mw.ustring.match((d or ""),"(%a+)") or "-")])
end
end
if (not day) and ((purif(string.match(m or "","(%d+)") or "") or 32) <= (monthd[month] or 31)) then
if (not day) and ((purif(string.match(m or "","(%d+)") or "") or 32) <= (monthd[month] or 31)) then
msg = category["params"]
msg = category.incomplete_parameters
day = purif(m:match("(%d+)") or "")
day = purif(m:match("(%d+)") or "")
end
end
if not year then
if not year then
msg = category["params"]
msg = category.incomplete_parameters
year = purif(string.match(m or "","(%d+)") or "")
year = purif(string.match(m or "","(%d+)") or "")
end
end
local function glue(d1,m1,y1,d2,m2,y2)
local 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) then
if (not d1) and (not m1) and (not y1) and (not d2) and (not m2) and (not y2) then
return category["params"] end
return category.incomplete_parameters end
local gd,gm,gy,jd,jm,jy =
local gd,gm,gy,jd,jm,jy =
(d1 or ""),
(d1 or ""),
return table.concat({comment[1],trim(trim(jd .. " " .. jm) .. " " .. jy ),
return table.concat({comment[1],trim(trim(jd .. " " .. jm) .. " " .. jy ),
comment[2]," ([[",trim(gd .. " " .. gm),"]]",gm_sep[1],(gy:match("(%d+)") or ""),
comment[2]," ([[",trim(gd .. " " .. gm),"]]",gm_sep[1],(gy:match("(%d+)") or ""),
gm_sep[2],gy,gm_sep[3],")",category["params"]})
gm_sep[2],gy,gm_sep[3],")",category.incomplete_parameters})
end
end
local args = getArgs(frame, { frameOnly = true })
local args = getArgs(frame, { frameOnly = true })
local datein = args[1]
local datein = args[1]
return p.bxDate( datein )
return (p.bxDate( datein ))
end
end
function p.bxDate( datein )
function 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 = tCon(errors.start,errors.no_data,errors.ending)
status.errorCat = category.no_parameters
status.brk = true
else
-- заполнение служебных таблиц
filling_months(lang, month_lang)
end
if not status.brk then
-- парсинг входящей даты по шаблону
-- заполнение служебных таблиц
date = parse_date(txtDateIn)
-- заменить сообщения об ошибках на списочные
if not (type(date.year) == 'number') then
status.errorText = tCon{
"<span class=error>Не удалось распознать год. Данные: ", unwarp(date),
"; ", txtDateIn ,"</span>"}
status.errorCat = category.incomplete_parameters
status.brk = true
end
if not (1 <= date.month and date.month <= 12) then
status.errorText = tCon{
"<span class=error>Не удалось распознать месяц. Данные: ", unwarp(date),
"; ", txtDateIn, "</span>"}
status.errorCat = category.incomplete_parameters
status.brk = true
end
if not date.day then
strFormat = trim(string.gsub(string.gsub(strFormat,"xg","F"),"[dDjlNwzW]",""))
elseif not (1 <= date.day and date.day <= month_end_day(date.month,date.year)) then
txtDateOut = table.concat({date.day,month_lang.ru_G[date.month],date.year}," ")
status.errorText = tCon{"<span class=error>Не удалось распознать день. Данные: ",
unwarp(date), "; ", txtDateIn, "</span>"}
status.errorCat = category.incomplete_parameters
status.brk = true
end
end
if not status.brk then
txtDateOut = mwlang:formatDate(strFormat,tCon({date.year,date.month,date.day},"-"),true)
end
return txtDateOut, date, status
return txtDateOut, date, status
end
end
function p.ToDate( frame ) -- возможно неиспользуемая
function p.ToDate( frame ) -- возможно неиспользуемая
local args = getArgs(frame, { frameOnly = true })
local args = getArgs(frame, { frameOnly = true })
local lang = mw.getContentLanguage()
local mwlang = mw.getContentLanguage()
local datein = args[1]
local datein = args[1]
local format = "j xg Y"
local format = "j xg Y"
else format = args[2]
else format = args[2]
end
end
return lang:formatDate(format,datein,true)
return mwlang:formatDate(format,datein,true)
end
end
mw.log("g1date " .. (undate(g1date ) or ""))
mw.log("g1date " .. (undate(g1date ) or ""))
mw.log("g2date " .. (undate(g2date ) or ""))
mw.log("g2date " .. (undate(g2date ) or ""))
return err .. category["params"]
return err .. category.incomplete_parameters
end
end
end
end
return p
return p