Documentation for this module may be created at Module:OpeningTimes/doc
local getArgs = require('Module:Arguments').getArgs
local Times = {}
function Times.main(frame)
local args = getArgs(frame)
local tableContainer = mw.html.create('table'):addClass('wikitable')
local headerRow = mw.html.create('tr')
:node(mw.html.create('th'):wikitext('Day'))
:node(mw.html.create('th'):wikitext('Opens'))
:node(mw.html.create('th'):wikitext('Closes'))
tableContainer:node(headerRow)
local monday = Times.createRow('Monday')
local tuesday = Times.createRow('Tuesday')
local wednesday = Times.createRow('Wednesday')
local thursday = Times.createRow('Thursday')
local friday = Times.createRow('Friday')
local saturday = Times.createRow('Saturday')
local sunday = Times.createRow('Sunday')
if args[247] or args.everyday then
local openingTime, closingTime = '00:00', '00:00'
if args.everyday then
local splitTime = mw.text.split(args.everyday, '-')
openingTime = splitTime[1]
closingTime = splitTime[2]
end
if args.monday == nil then monday:node(Times.setTime(openingTime)):node(Times.setTime(closingTime)) end
if args.tuesday == nil then tuesday:node(Times.setTime(openingTime)):node(Times.setTime(closingTime)) end
if args.wednesday == nil then wednesday:node(Times.setTime(openingTime)):node(Times.setTime(closingTime)) end
if args.thursday == nil then thursday:node(Times.setTime(openingTime)):node(Times.setTime(closingTime)) end
if args.friday == nil then friday:node(Times.setTime(openingTime)):node(Times.setTime(closingTime)) end
if args.saturday == nil then saturday:node(Times.setTime(openingTime)):node(Times.setTime(closingTime)) end
if args.sunday == nil then sunday:node(Times.setTime(openingTime)):node(Times.setTime(closingTime)) end
else
if args.weekdays then
local splitTime = mw.text.split(args.weekdays, '-')
if args.monday == nil then monday:node(Times.setTime(splitTime[1])):node(Times.setTime(splitTime[2])) end
if args.tuesday == nil then tuesday:node(Times.setTime(splitTime[1])):node(Times.setTime(splitTime[2])) end
if args.wednesday == nil then wednesday:node(Times.setTime(splitTime[1])):node(Times.setTime(splitTime[2])) end
if args.thursday == nil then thursday:node(Times.setTime(splitTime[1])):node(Times.setTime(splitTime[2])) end
if args.friday == nil then friday:node(Times.setTime(splitTime[1])):node(Times.setTime(splitTime[2])) end
end
if args.weekend then
local splitTime = mw.text.split(args.weekend, '-')
if args.saturday == nil then saturday:node(Times.setTime(splitTime[1])):node(Times.setTime(splitTime[2])) end
if args.sunday == nil then sunday:node(Times.setTime(splitTime[1])):node(Times.setTime(splitTime[2])) end
end
end
if args.monday then
local splitTime = mw.text.split(args.monday, '-')
monday:node(Times.setTime(splitTime[1])):node(Times.setTime(splitTime[2]))
end
if args.tuesday then
local splitTime = mw.text.split(args.tuesday, '-')
tuesday:node(Times.setTime(splitTime[1])):node(Times.setTime(splitTime[2]))
end
if args.wednesday then
local splitTime = mw.text.split(args.wednesday, '-')
wednesday:node(Times.setTime(splitTime[1])):node(Times.setTime(splitTime[2]))
end
if args.thursday then
local splitTime = mw.text.split(args.thursday, '-')
thursday:node(Times.setTime(splitTime[1])):node(Times.setTime(splitTime[2]))
end
if args.friday then
local splitTime = mw.text.split(args.friday, '-')
friday:node(Times.setTime(splitTime[1])):node(Times.setTime(splitTime[2]))
end
if args.saturday then
local splitTime = mw.text.split(args.saturday, '-')
saturday:node(Times.setTime(splitTime[1])):node(Times.setTime(splitTime[2]))
end
if args.sunday then
local splitTime = mw.text.split(args.sunday, '-')
sunday:node(Times.setTime(splitTime[1])):node(Times.setTime(splitTime[2]))
end
return tableContainer:node(monday):node(tuesday):node(wednesday):node(thursday):node(friday):node(saturday):node(sunday)
end
function Times.createRow(text)
return mw.html.create('tr'):node(mw.html.create('th'):attr('scope', 'row'):wikitext(text))
end
function Times.setTime(timeStr)
return mw.html.create('td'):wikitext(Times.editTime(timeStr))
end
function Times.editTime(str)
-- If string already has : in it
if string.find(str, ':') then
if #mw.text.split(str, ':')[1] == 1 then str = '0' .. str end
return str
else
if #str == 1 then str = '0' .. str end
return str .. ':00'
end
end
return Times