Module:Countdown
لاسوند لپاره ددې موډيول کېدای سی په Module:Countdown/لاسوند کي وي
-- This module powers {{countdown}}.
local p = {}
-- Constants
local lang = mw.language.getContentLanguage()
local getArgs = require('Module:Arguments').getArgs
function formatMessage(secondsLeft, event, color, refreshLink)
local timeLeft = lang:formatDuration(secondsLeft, {'years', 'weeks', 'days', 'hours', 'minutes', 'seconds'})
-- Find whether we are plural or not.
-- no use to us.
-- no use to us.
-- no use to us.
-- no use to us.
-- no use to us.
-- no use to us.
-- Color and bold the numbers, because it makes them look important.
local timeLeft = mw.ustring.gsub(timeLeft, '(%d+)', '<span style="color: ' .. (color or '#F00') .. '; font-weight: bold;">%1</span>')
-- Make the refresh link and join it all together.
return mw.ustring.format('تر %s %s پورې پاتې ده.%s', event, timeLeft, refreshLink)
end
function p.main(frame)
local args = getArgs(frame)
if not (args["کال"] and args["میاشت"] and args["ورځ"]) then
return '<strong class="error">تېروتنه: کال، میاشت، او ورځ باید مشخص سی</strong>'
end
local eventTime = os.time{year=args["کال"], month=args["میاشت"], day=args["ورځ"], hour=args["ساعت"], min=args["دقیقه"], sec=args["ثانیه"]}
local timeToStart = os.difftime(eventTime, os.time()) -- (future time - current time)
local refreshLink = mw.title.getCurrentTitle():fullUrl{action = 'purge'}
refreshLink = mw.ustring.format(' <small><span class="plainlinks">([%s تازه کونه])</span></small>', refreshLink)
if timeToStart > 0 then
-- Event has not begun yet
return formatMessage(timeToStart, args["پيښه"] or 'پیښه پیل کړئ', args["رنګ"], refreshLink)
elseif args["وخت"] then
local timeToEnd
if args["یو مدت"] then
-- Duration is in unit other than seconds, use formatDate to add
timeToEnd = tonumber(lang:formatDate('U', '@' .. tostring(timeToStart) .. ' +' .. tostring(args["مدت"]) .. ' ' .. args["یو مدت"]))
else
timeToEnd = timeToStart + tonumber(args["مدت"])
end
if timeToEnd > 0 then
-- Event is in progress
return args["پیښه پیل کړئ"] .. refreshLink or formatMessage(timeToEnd, (args["پیښه"] or 'پیښه') .. ' ends', args["پیښه"], refreshLink)
else
-- Event had a duration and has now ended
return ((args["پيښه پایته رسېدنه"] or ((args["پیښه"] or 'پیښه') .. ' ختمیدنه وموند.')) .. refreshLink)
end
else
-- Event had no duration and has begun
return ((args["د پيښې شروع"] or ((args["پیښه"] or 'پیښه') .. ' شروع سو.')) .. refreshLink)
end
end
return p