-- This module powers {{countdown}}.
local p = {}
-- Constants
local lang = mw.language.getContentLanguage()
local getArgs = require('Module:Arguments').getArgs
local yn = require("Module:Yesno")
local floor = math.floor
local mod = math.fmod
function getSystemMessage(name, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
return mw.getCurrentFrame():callParserFunction("int", name, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
end
function p.main(frame)
local args = getArgs(frame)
local timeInput = args['time'] or args[1]
local offset = args['offset'] or args[2]
local shorthand = yn(args['shorthand'])
local timestamp = tonumber(frame:preprocess("{{#time:U|" .. timeInput .. "|}}"))
local currentTime = tonumber(frame:preprocess("{{#time:U}}"))
local time_days = floor((timestamp - currentTime) / 86400)
local time_hours = floor(mod((timestamp - currentTime) / 3600, 24))
local time_minutes = floor(mod((timestamp - currentTime) / 60, 60))
local time_seconds = floor(mod((timestamp - currentTime), 60))
local out = ''
if shorthand then
-- clip the first letter of each display
local secondDisplay, minuteDisplay, hourDisplay, dayDisplay
secondDisplay = mw.ustring.sub(getSystemMessage("seconds", ""), 0, 1)
minuteDisplay = mw.ustring.sub(getSystemMessage("minutes", ""), 0, 1)
hourDisplay = mw.ustring.sub(getSystemMessage("hours", ""), 0, 1)
dayDisplay = mw.ustring.sub(getSystemMessage("days", ""), 0, 1)
if time_days > 0 then
out = out .. time_days .. dayDisplay .. " "
end
if time_hours > 0 then
out = out .. time_hours .. hourDisplay .. " "
end
if time_minutes > 0 then
out = out .. time_minutes .. minuteDisplay .. " "
end
if time_seconds > 0 then
out = out .. time_seconds .. secondDisplay .. " "
end
else
if time_days > 0 then
out = out .. time_days .. dayDisplay .. " "
end
if time_hours > 0 then
out = out .. time_hours .. hourDisplay .. " "
end
if time_minutes > 0 then
out = out .. time_minutes .. minuteDisplay .. " "
end
if time_seconds > 0 then
out = out .. time_seconds .. secondDisplay .. " "
end
end
return '<span style="' .. args['style'] .. '">' .. out .. '</span> ' .. frame:preprocess("([{{fullurl:{{FULLPAGENAMEE}}|action=purge}} Update])")
end
return p