Модуль:Пісочниця/Repakr/testcs1
Перейти до навігації
Перейти до пошуку
Документація модуля[створити]
Зараз цей модуль не має відповідної документації. Якщо вам відомі призначення та засади використання цього модуля, будь ласка, напишіть хоча б коротеньку документацію. |
Дописувачі можуть експериментувати на підсторінках пісочниця (створити | дзеркало) та протестувати зміни (ред.) цього модуля. Підсторінки цієї сторінки. |
-- {{Шаблон:Документація/end box/пісочниця}}
local genitivusMonthes = {'січня', 'лютого', 'березня', 'квітня', 'травня', 'червня',
'липня', 'серпня', 'вересня', 'жовтня', 'листопада', 'грудня'}
local function extract_era (frame)
for item in frame.args[1]:gsub(',', ' '):gsub(' ', ' '):gmatch('(до%s)?%S+') do
if item == "до н.е." then
return true
end
end
return false
end
local function is_set( var )
return not (var == nil or var == '');
end
local function strip_to_nil(text)
-- If text is a string, return its trimmed content, or nil if empty.
-- Otherwise return text (convenient when Date fields are provided from
-- another module which may pass a string, a number, or another type).
if type(text) == 'string' then
text = mw.ustring.match(text, '(%S.-)%s*$')
end
return text
end
local function numberTest(frame)
return (tonumber(frame.args[1]))
end
function Date2(frame)
return strip_to_nil(frame.args[1])
end
function Date(frame)
if frame.args.date then
frame.args.date = mw.ustring.gsub(frame.args.date, "(%d%d%d%d)%a", "%1")
end
return frame.args.date
end
local function textReplace()
local format = "%e %B %Y"
return format:gsub("e", "d")
end
local function name_to_number(text, translate)
if type(text) == 'string' then
return translate[text:lower()]
end
end
local function month_number(frame)
return name_to_number(frame.args[1], {
['січня'] = 1
})
end
local function getDate (frame)
local Date = require('Module:Date/пісочниця')._Date
local text = Date(frame.args[1])
return text;
end
local function getDate2 (frame)
local Date = require('Модуль:DateI18n')._Date
local text = Date(frame.args[1], "uk")
return text;
end
function snowflakeToDate(frame)
local format = frame.args.format or "%e %B %Y"
local epoch = tonumber(frame.args.epoch) or 1288834974
local id_str = frame.args.id_str
if type(id_str) ~= "string" then error("bad argument #1 (expected string, got " .. type(id_str) .. ")", 2) end
if type(format) ~= "string" then error("bad argument #2 (expected string, got " .. type(format) .. ")", 2) end
if type(epoch) ~= "number" then error("bad argument #3 (expected number, got " .. type(epoch) .. ")", 2) end
local hi, lo = 0, 0
local hiexp = 1
local two32 = 2^32
for c in id_str:gmatch(".") do
lo = lo * 10 + c
if lo >= two32 then
hi, lo = hi * 10^hiexp + math.floor(lo / two32), lo % two32
hiexp = 1
else hiexp = hiexp + 1 end
end
hi = hi * 10^(hiexp-1)
local timestamp = math.floor((hi * 1024 + math.floor(lo / 4194304)) / 1000) + epoch
return os.date(format, timestamp)
end
local function lowercase ()
local possibleDateString = "12 січня 2023"
local day, month, year = mw.ustring.match(possibleDateString, "^([1-9]%d?)%s(%a+)%s(%d%d%d%d)$")
-- return "day: " .. day .. " month: " .. month .. " year: " .. year
if (day and month and year) then
local numMonth = convertToNumericMonth (month)
return numMonth
end
return false
end
local function toutf8 (frame)
return mw.ustring.codepoint(frame.args[1])
end
local function is_Cyrillic (codepoint)
return (codepoint >= 1024 ) and (codepoint <= 1327)
end
local function texttoutf8 (frame)
local result = false;
for codepoint in mw.ustring.gcodepoint( frame.args[1] ) do
local is_script = is_Cyrillic(codepoint)
if is_script then
result = true
else
return false
end
end
return result
end
function convertToNumericMonth (aMonth)
for n,v in ipairs( genitivusMonthes ) do
if v == aMonth then
return n;
end
end
end
local function list_of_languages (frame)
local this_wiki_code = mw.getContentLanguage():getCode()
local lang_table = mw.language.fetchLanguageNames (mw.getContentLanguage():getCode(), 'all')
local code = frame.args[1]
local name = lang_table[code]
local tip
local shorten_name
local lang_short_t = {
["ko"] = "кор.",
["en"] = "англ."
}
if mw.ustring.match(name, "ка$") then
tip = name:gsub('а$', '') .. "ою мовою"
else
tip = "мовою " .. name
end
if lang_short_t[code] then
shorten_name = lang_short_t[code]
else
shorten_name = name
end
local wraped = '<span title="' .. tip ..'" style="font-size:85%; cursor:help; margin-left:0.2em; color:#888;">('.. shorten_name ..')</span>'
return wraped;
end
local function currentProt (frame)
local titleObj = mw.title.new(frame.args[1])
currentProt = titleObj.protectionLevels["edit"][1]
return currentProt;
end
local function list_of_all_languages ()
local this_wiki_code = mw.getContentLanguage():getCode()
local lang_table = mw.language.fetchLanguageNames (mw.getContentLanguage():getCode(), 'all')
local result = ""
for k, v in pairs(lang_table) do
result = result .. "[" .. k .. "] = " .. v .."<br/>"
end
return result
end
local function sixty_trans (number)
local integer, remainder
if number % 60 == 0 then
integer = number / 60
return integer, 0
else
integer = math.floor(number / 60)
remainder = number - (60*integer)
return integer, remainder
end
end
local function total_length (frame)
local total = {
sec = {0, 'min'},
min = {0, 'hour'},
hour = {0, ''},
}
for k, item in pairs (frame.args) do
local hour, min, sec
hour, min, sec = item:match('^(%d+):(%d+):(%d+)$')
if not seconds then
min, sec = item:match('^(%d+):(%d+)$')
total.min[1] = total.min[1] + tonumber(min)
total.sec[1] = total.sec[1] + tonumber(sec)
else
total.hour[1] = total.hour[1] + tonumber(hour)
total.min[1] = total.min[1] + tonumber(min)
total.sec[1] = total.sec[1] + tonumber(sec)
end
end
for key, item in pairs(total) do
integer, remainder = sixty_trans (item[1])
if not (item[2] == '' and integer == 0) then
local index = item[2]
total[index][1] = total[index][1] + integer
item[1] = remainder
end
end
local result
if total.hour[1] == 0 then
result = total.min[1] .. ':' .. total.sec[1]
else
result = total.hour[1] .. ':' .. total.min[1] .. ':' .. total.sec[1]
end
return result
end
local function test_documention ()
local frame = mw.getCurrentFrame()
return frame:expandTemplate{ title = 'Документація/end box/пісочниця', }
end
local function yesno(frame)
local yesno = require("Module:Yesno")
return yesno(nil)
end
return {
lowercase = lowercase;
toutf8 = toutf8;
texttoutf8= texttoutf8;
snowflakeToDate = snowflakeToDate;
getDate = getDate;
getDate2 = getDate2;
month_number = month_number;
textReplace = textReplace;
Date = Date;
Date2 = Date2;
numberTest= numberTest;
extract_era = extract_era;
list_of_languages = list_of_languages;
currentProt = currentProt;
list_of_all_languages = list_of_all_languages;
total_length = total_length;
yesno = yesno;
test_documention = test_documention;
};