Module:Sandbox/DannyS712/remind

-- This module powers.

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, {'years', 'weeks', 'days', 'hours', 'minutes', 'seconds'}) -- Find whether we are plural or not. local isOrAre if string.match(timeLeft, '^%d+') == '1' then isOrAre = 'is' else isOrAre = 'are' end -- Color and bold the numbers, because it makes them look important. local timeLeft = string.gsub(timeLeft, '(%d+)', '%1 ') -- 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 ' Error: year, month, and day must be specified ' end if not (args.reminder) then return ' Error: reminder must be specified ' 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)

if timeToStart > 0 then -- Reminder still pending return '' else -- Reminder due return args.reminder end end

return p