Jump to content

Module:Daterange: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
create
 
allow unnamed parameters
Line 4: Line 4:
local ranges = {}
local ranges = {}


s = (args.start or args[1] or "")
if ((args.start or "") ~= "") then
if (s ~= "") then
e = args["end"] or ""
e = args["end"] or args[2] or ""
if e:sub(0,-3) == args.start:sub(0,2) then
if e:sub(0,-3) == s:sub(0,2) then
e = e:sub(-2,-1)
e = e:sub(-2,-1)
end
end
table.insert(output, args.start.." – "..e)
table.insert(output, s.." – "..e)
end
end

Revision as of 23:05, 23 February 2023

return { main = function(frame)
	local args = require('Module:Arguments').getArgs(frame)
	local output = {}
	local ranges = {}

	s = (args.start or args[1] or "")
	if (s ~= "") then
		e = args["end"] or args[2] or ""
		if e:sub(0,-3) == s:sub(0,2) then
			e = e:sub(-2,-1)
		end
		table.insert(output, s.." – "..e)
	end
	
	for k, v in pairs(args) do
		if ((v or "") ~= "") and (k:sub(0,5) == "start") and tonumber(k:sub(6,-1)) then
			num = tonumber(k:sub(6,-1))
			if num and num > 0 then
				e = args["end"..num] or ""
				if e:sub(0,-3) == v:sub(0,2) then
					e = e:sub(-2,-1)
				end
				ranges[num] = v.." – "..e
			end
		end
	end
	
	for i, v in ipairs( ranges ) do
    	table.insert(output, v)
	end
	
	return table.concat(output, ", ")
end }