Module:Year sequence: Difference between revisions
Robertbaxter (talk | contribs) (Created page with "local p = {} function p.consolidate(frame) local args = frame.args or frame:getParent().args local source = args[1] --[[ local terminus = tonumber(args[2]) local suffix = args[3] ]]-- local a = {} for year in string.gmatch(source, "%d%d%d%d") do table.insert(a, tonumber(year)) end table.sort(a) local result = "" local prev = 0 local range = false for year in a do if year == prev + 1 then --YEAR IS ONE ABOVE PREVIOUS YEAR-- if not range then...") |
Robertbaxter (talk | contribs) No edit summary |
||
Line 3: | Line 3: | ||
function p.consolidate(frame) | function p.consolidate(frame) | ||
local args = frame.args or frame:getParent().args | local args = frame.args or frame:getParent().args | ||
local a = {} | local a = {} | ||
for year in string.gmatch(source, "%d%d%d%d") do | for year in string.gmatch(source, "%d%d%d%d") do |
Revision as of 21:30, 21 December 2024
Documentation for this module may be created at Module:Year sequence/doc
local p = {}
function p.consolidate(frame)
local args = frame.args or frame:getParent().args
local a = {}
for year in string.gmatch(source, "%d%d%d%d") do
table.insert(a, tonumber(year))
end
table.sort(a)
local result = ""
local prev = 0
local range = false
for year in a do
if year == prev + 1 then
--[[YEAR IS ONE ABOVE PREVIOUS YEAR]]--
if not range then
--[[START A RANGE]]--
result = result .. "–"
range = true
end
else
if range then
--[[RANGE ENDED WITH PREV]]--
result = result .. prev
range = false
end
if result ~= "" then result = result .. ", " end
result = result .. year
end
prev = year
end
if range then
--[[RANGE ENDED WITH PREV]]--
result = result .. prev
range = false
end
return result
end
return p