Module:Position history: Difference between revisions
Jump to navigation
Jump to search
(create) |
mNo edit summary |
||
Line 15: | Line 15: | ||
function p.main(frame) | function p.main(frame) | ||
p.call(frame:getParent().args) | return p.call(frame:getParent().args) | ||
end | end | ||
Revision as of 19:39, 5 October 2020
Documentation for this module may be created at Module:Position history/doc
local datediff = require('Module:Date difference').call
local p = {}
local function argDefault(arg, default)
if not arg or arg == '' then
return default or ''
else
return arg
end
end
local function makeCell(content)
return '\t\t<td>' .. content .. '</td>\n'
end
function p.main(frame)
return p.call(frame:getParent().args)
end
function p.call(args)
local incumbentString = '—'
local html = ''
local num = 1
local row, holder, startDate, endDate
repeat
holder = argDefault(args[num], '{{{' .. num .. '}}}')
startDate = argDefault(args[num + 1], 'unknown')
endDate = argDefault(args[num + 2], 'unknown')
row = '\t<tr>\n'
if (endDate == 'unknown' or endDate == incumbentString) and num == 1 then
endDate = incumbentString
row = '\t<tr style="font-weight:bold;">\n'
end
row = row .. makeCell(startDate) .. makeCell(holder) .. makeCell(endDate)
if startDate ~= 'unknown' and endDate ~= 'unknown' then
if endDate == incumbentString then
row = row .. makeCell(datediff({ startDate }) .. ' Days')
else
row = row .. makeCell(datediff({ startDate, endDate }) .. ' Days')
end
else
row = row .. makeCell('? Days')
end
row = row .. '\t</tr>\n'
html = html .. row
num = num + 3
until not args[num]
return html
end
return p