Jump to content

Module:Daterange

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Ahecht (talk | contribs) at 23:03, 23 February 2023 (create). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

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

	
	if ((args.start or "") ~= "") then
		e = args["end"] or ""
		if e:sub(0,-3) == args.start:sub(0,2) then
			e = e:sub(-2,-1)
		end
		table.insert(output, args.start.." – "..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 }