Module:Sandbox/Shahar: Difference between revisions
From Inkipedia, the Splatoon wiki
m (Tweaking Module:Countdown) |
m (more tweaks) |
||
Line 19: | Line 19: | ||
if timeToStart > 0 then | if timeToStart > 0 then | ||
-- Event has not begun yet | -- Event has not begun yet | ||
text = args.eventbefore | text = args.eventbefore or ((lang:ucfirst(args.event or 'The event')) .. ' has not begun yet.') | ||
elseif args.duration then | elseif args.duration then | ||
local timeToEnd | local timeToEnd | ||
Line 30: | Line 30: | ||
if timeToEnd > 0 then | if timeToEnd > 0 then | ||
-- Event is in progress | -- Event is in progress | ||
text = args.eventstart or ((lang:ucfirst(args.event or 'The event')) .. ' | text = args.eventstart or ((lang:ucfirst(args.event or 'The event')) .. ' is in progress.') | ||
else | else | ||
-- Event had a duration and has now ended | -- Event had a duration and has now ended |
Revision as of 16:24, 2 October 2022
Documentation for this module may be created at Module:Sandbox/Shahar/doc
-- This module powers {{User:Shahar/Test/4}}. replacement to static countdown local p = {} -- Constantsco local lang = mw.language.getContentLanguage() local getArgs = require('Module:Arguments').getArgs 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.year, month=args.month, day=args.day, hour=args.hour, min=args.minute, sec=args.second}) local timeToStart = os.difftime(eventTime, os.time()) -- (future time - current time) local text if timeToStart > 0 then -- Event has not begun yet text = args.eventbefore or ((lang:ucfirst(args.event or 'The event')) .. ' has not begun yet.') 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) or error('args.duration should be a number of seconds', 0)) end if timeToEnd > 0 then -- Event is in progress text = args.eventstart or ((lang:ucfirst(args.event or 'The event')) .. ' is in progress.') else -- Event had a duration and has now ended text = args.eventend or ((lang:ucfirst(args.event or 'The event')) .. ' has ended.') end else -- Event had no duration and has begun text = args.eventstart or ((lang:ucfirst(args.event or 'The event')) .. ' has started.') 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 refresh])</span></small>', refreshLink) end return text .. refreshLink end return p