Module:Sandbox/BrandonXLF/1: Difference between revisions

Content deleted Content added
No edit summary
Tag: Reverted
Restored revision 1025694786 by BrandonXLF (Restorer)
Line 1:
-- Sandbox, do not delete
local p = {}
 
function main (frame, switch)
local monthsAbbr = {
local fArgs = frame.args
'Jan',
local pArgs = frame:getParent().args
'Feb',
local tArgs = {}
'Mar',
local template = fArgs['_']
'Apr',
if not template then
'May',
return require('Module:Error').error{'Error: No template name given.'}
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec'
}
 
local months = {
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
}
 
local function getMaxDay(month, year)
local maxDay
if month == 1
or month == 3
or month == 5
or month == 7
or month == 8
or month == 10
or month == 12
then
maxDay = 31
elseif month == 2 then
if year % 400 == 0 then
maxDay = 29
elseif year % 100 == 0 then
maxDay = 28
elseif year % 4 == 0 then
maxDay = 29
else
maxDay = 28
end
else
maxDay = 30
end
fArgs._ = nil
if switch then
return maxDay
pArgs, fArgs = fArgs, pArgs
end
 
local function incrementDate(date)
date.day = date.day + 1
 
if date.day > date.maxDay then
date.day = 1
date.month = date.month + 1
date.maxDay = getMaxDay(date.month, date.year)
if date.month > 12 then
date.month = 1
date.year = date.year + 1
end
end
for k, v in pairs(fArgs) do
end
tArgs[k] = v
 
local function createDate(year, month, day)
return {
day = day,
maxDay = getMaxDay(month, year),
month = month,
year = year
}
end
function p.main()
local currentDate = os.date('!*t')
local date = createDate(2010, 12, 1)
local out = '<table>'
local currentMonth
local currentYear
while true do
if date.year > currentDate.year then
break
end
if date.year == currentDate.year then
if date.month > currentDate.month then
break
end
if date.month == currentDate.month and date.day > currentDate.day then
break
end
end
if date.year ~= currentYear then
out = out .. '</td></tr></table><h2>' .. date.year .. '</h2><table>'
currentYear = date.year
end
if date.month ~= currentMonth then
out = out .. '</td></tr><tr><th scope="row" style="text-align:left;">' .. monthsAbbr[date.month] .. '</th><td>'
currentMonth = date.month
end
local dateString = date.year .. ' ' .. months[date.month] .. ' ' .. date.day
out = out .. '[[Wikipedia:Main Page history/' .. dateString .. '|' .. date.day .. ']]' .. '/[[Wikipedia:Main Page history/' .. dateString .. 'b|b]] '
incrementDate(date)
end
for k, v in pairs(pArgs) do
tArgs[k] = v
return out .. '</td></tr></table>'
end
return frame:expandTemplate{title = template, args = tArgs}
end
 
return p{
default = function (frame) return main(frame) end,
force = function (frame) return main(frame, true) end
}