Jump to content

Module:Daterange: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
consistent range
Don't show dash with single date
 
Line 11: Line 11:
e = e:sub(-2,-1)
e = e:sub(-2,-1)
end
end
output[num] = v.."–"..e
output[num] = v..(e~="" and "–"..e or "")
end
end
end
end
Line 22: Line 22:
e = e:sub(-2,-1)
e = e:sub(-2,-1)
end
end
table.insert(output, 1, s.."–"..e)
table.insert(output, 1, s..(e~="" and "–"..e or ""))
end
end



Latest revision as of 02:20, 24 February 2023

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

	for k, v in pairs(args) do
		if (type(k) == "string") and ((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,-3) then
					e = e:sub(-2,-1)
				end
				output[num] = v..(e~="" and "–"..e or "")
			end
		end
	end
	
	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,-3) then
			e = e:sub(-2,-1)
		end
		table.insert(output, 1, s..(e~="" and "–"..e or ""))
	end

	return table.concat(output, ", ")
end }