Modul:Countdown
Qiyofa
Bu modul uchun Modul:Countdown/doc nomli hujjat sahifasini yaratishingiz mumkin
local p = {}
local lang = mw.language.getContentLanguage()
local getArgs = require('Module:Arguments').getArgs
local function formatMessage(secondsLeft, boshmatn, oxirgimatn, color)
local timeLeft = lang:formatDuration(secondsLeft, {'days', 'hours', 'minutes'})
timeLeft = string.gsub(timeLeft, 'kun, ', 'kun ')
timeLeft = string.gsub(timeLeft, 'hoursva', 'soat ')
timeLeft = string.gsub(timeLeft, 'minutes', 'daqiqa')
timeLeft = string.gsub(timeLeft, '(%d+)', '<span style="color: ' .. (color or '#F00') .. '; font-weight: bold;">%1</span>')
return string.format('%s %s %s', boshmatn, timeLeft, oxirgimatn)
end
function p.main(frame)
local args = getArgs(frame)
if not (args.y and args.o and args.k) then
return '<strong class="error">Xatolik: Yil, oy va kun maʼlumoti kiritilmadi</strong>'
end
local timeArgs = {year=args.y, month=args.o, day=args.k, hour=args.s, min=args.m, sec=args.sek}
for k,v in pairs(timeArgs) do
if not tonumber(v) then
error('Argument ' .. k .. ' could not be parsed as a number: ' .. v)
end
end
local eventTime = os.time(timeArgs)
local timeToStart = os.difftime(eventTime, os.time()) -- (future time - current time)
local boshmatn
if timeToStart > 0 then
if not args.u then
text = formatMessage(timeToStart, args.boshmatn or 'Munozara yopilishigacha', args.oxirgimatn or 'qoldi.', args.color)
else
text = formatMessage(timeToStart, args.boshmatn or 'Agar muddat oxirigacha [[Vikipediya:Konsensus|konsensus]]ga erishilmasa, muhokama uchun qoʻshimcha vaqt beriladi.', args.oxirgimatn or 'keyin yopilishi kerak.', args.color)
end
elseif args.duration then
local timeToEnd
if args['duration unit'] then
timeToEnd = tonumber(lang:formatDate('U', '@' .. tostring(timeToStart) .. ' +' .. tostring(args.duration) .. ' ' .. args['duration unit']))
else
timeToEnd = timeToStart + (tonumber(args.duration) or error('args.duration should be a number of seconds', 0))
end
if timeToEnd > 0 then
text = args.eventstart or formatMessage(timeToEnd, (args.event or 'the event') .. ' ends', args.color)
else
text = args.eventend or ((lang:ucfirst(args.event or 'The event')) .. ' has ended.')
end
else
text = args.eventstart or ((lang:ucfirst(args.event or 'Muhokama uchun ajratilgan muddat')) .. ' tugadi.')
end
local refreshLink
if args.refresh == 'no' then
refreshLink = ''
else
refreshLink = mw.title.getCurrentTitle():fullUrl({action = 'purge'})
refreshLink = string.format(' <small><span class="plainlinks">([%s yangilash])</span></small>', refreshLink)
end
return text .. refreshLink
end
return p