Módulu:Countdown

De Wikipedia

La documentación pa esti módulu pue crease en Módulu:Countdown/usu

-- This module powers {{countdown}}.

local p = {}

-- Constants
local lang = mw.language.getContentLanguage()
local getArgs = require('Module:Arguments').getArgs

local function formatMessage(secondsLeft, event, color, refreshLink)
	local timeLeft = lang:formatDuration(secondsLeft, {'años', 'selmanes', 'díes', 'hores', 'minutos', 'segundos'})
	-- Find whether we are plural or not.
	local isOrAre
	if string.match(timeLeft, '^%d+') == '1' then
		isOrAre = 'ye'
	else
		isOrAre = 'son'
	end
	-- Color and bold the numbers, because it makes them look important.
	local timeLeft = string.gsub(timeLeft, '(%d+)', '<span style="color: ' .. (color or '#F00') .. '; font-weight: bold;">%1</span>')
	-- Make the refresh link and join it all together.
	return string.format('There %s %s until %s.%s', isOrAre, timeLeft, event, refreshLink)
end

function p.main(frame)
	local args = getArgs(frame)

	if not (args.year and args.month and args.day) then
		return  '<strong class="error">Error: year, month, and day must be specified</strong>'
	end

	local eventTime = os.time({year=args.anu, month=args.mes, day=args.dia, hour=args.hora, min=args.minutu, sec=args.segundu})
	local timeToStart = os.difftime(eventTime, os.time()) -- (future time - current time)

	local refreshLink = mw.title.getCurrentTitle():fullUrl({action = 'purge'})
	refreshLink = string.format(' <small><span class="plainlinks">([%s refresh])</span></small>', refreshLink)
	if timeToStart > 0 then
		-- Event has not begun yet
		return formatMessage(timeToStart, args.event or 'l&#8217;eventu entama', args.color, refreshLink)
	elseif args.duration then
		local timeToEnd
		if args['duration unit'] then
			-- Duration is in unit other than seconds, use formatDate to add
			timeToEnd = tonumber(lang:formatDate('U', '@' .. tostring(timeToStart) .. ' +' .. tostring(args.duration) .. ' ' .. args['duration unit']))
		else
			timeToEnd = timeToStart + tonumber(args.duration)
		end
		if timeToEnd > 0 then
			-- Event is in progress
			return args.eventstart .. refreshLink or formatMessage(timeToEnd, (args.event or 'l&#8217;eventu entama') .. ' ends', args.color, refreshLink)
		else
			-- Event had a duration and has now ended
			return (args.eventend or ((lang:ucfirst(args.event or 'L&#8217;eventu entama')) .. ' remató.')) .. refreshLink
		end
	else
		-- Event had no duration and has begun
		return (args.eventstart or ((lang:ucfirst(args.event or 'L&#8217;eventu entama')) .. ' entamó.')) .. refreshLink
	end
end

return p