Ir al contenido

Módulo:Zona de pruebas/Ismerp22

De Wikipedia, la enciclopedia libre
Este módulo no tiene página de documentación[crear]
-- Este módulo lo utiliza {{...}}.

local p = {}

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

local function formatMessage(secondsLeft, event, color, textoFaltan)
	local timeLeft = lang:formatDuration(secondsLeft, {'years', 'weeks', 'days', 'hours', 'minutes', 'seconds'})

--	if 
string.match(timeLeft, '^%d+')
-- == '1' ---then
--		isOrAre = 'is'
--	else
--		isOrAre = 'are'
--	end
	timeLeft = string.gsub(timeLeft, '(%d+)', '<span style="color: ' .. (color or '#F00') .. '; font-weight: bold;">%1</span>')
	return string.format((textoFaltan or 'Faltan')..' %s para %s.', 
--isOrAre, 
 timeLeft, event)
end

function p.ConteoRegresivo(frame)
	local args = getArgs(frame)
 
	if not (args.year and args.month and args.day) then
		return '<strong class="error">Error: debe especificar el año, el mes y el día.</strong>'
	end

	local timeArgs = {year=args.year, month=args.month, day=args.day, hour=args.hour, min=args.minute, sec=args.second}
	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())
	local text
	if timeToStart > 0 then
		-- Event has not begun yet
		text = formatMessage(timeToStart, args.event or 'the event begins', args.color, args.faltan or args.textofaltan or args.f)
 if args.f == 'no' then 
      textoFaltan = ' '
	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
			-- Event is in progress
			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 'The event')) .. ' has started.')
	end

-- Enlace a purgar y el texto que aparecerá en el enlace es personalizable
       local textoPurge = args.textopurge or args.purgetexto or args.Purgetexto
	local refreshLink
	if args.purgar or args.Purgar == 'no' then
		refreshLink = ''
	else
		refreshLink = mw.title.getCurrentTitle():fullUrl({action = 'purge'})
		refreshLink = string.format(' <small><span class="plainlinks">([%s '..(textoPurge or 'actualizar')..'])</span></small>', refreshLink)
	end
	return text .. refreshLink
 end
end
return p