Module:TimeSwitch

-- Tests for Module:TimeSwitch are in the /testcases subpage --

-- -- This module displays different text based on the current date. -- It reuqires a table of numbered arguments which are any string alternating with a date-string. -- The parameter list can be read as follow: -- -- Display *param1* until the date specified in *param2* is reached. -- If the date specified in *param2* is reached, -- display *param3* until the time specified in *param4* is reached. -- -- This template supports an unlimited amount of passed parameters. -- If the last passed date is over, the invoking page will automatically -- be added to the category "Pages with unneded TimeSwitches" so that no longer necessary -- calls to this module can be removed to improve page-generation time. -- -- @see http://tieske.github.io/date/

local getArgs = require('Dev:Arguments').getArgs local date = require('Dev:Date')

local p = {}

-- -- Main entry point to be called from the templates. -- It processes the frame arguments. Arguments of hte function p.main(frame) local args = getArgs(frame)

return p._main(args) end

-- -- Intermal main function. Only handles a table of arguments and not the complate frame. -- -- @param args A table of arguments. Must be any string and a date-string alternating --              in any number of repetitions. -- -- @return  One of the strings in the parameter list. -- function p._main(args) local category = "" local i = 1 while args[i] or args[i+1] do       if args[i+1] == nil then return args[i] .. category elseif date(args[i+1]) >= date then if args[i] == nil then return "" end return args[i] end i = i + 2; end return category end

return p

-- --