Module:Age range

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

local p = {}

function p.ageRange(frame)
	local args = frame.args
	local year1 = tonumber(args[1])
	local year2 = tonumber(args[2])
	local currentYear = tonumber(os.date('%Y'))

	if not year1 or not year2 then return '' end

	local age1 = currentYear - year2
	local age2 = currentYear - year1

	if age1 == age2 then
		return age1
	else
		return age1 .. '–' .. age2
	end
end

return p