Documentation for this module may be created at Modulu:Date/dok

local p = {}

-- Input: year
-- Output: locative genitive form of year (+ko or +eko)
-- See Template:Epentesi kalkulagailua
function p.genitive_year(value, linked)
	
	-- from template via invoke or from module via require
	if type(value) == "table" then
		year = value.args[1]
		linked = value.args[2]
	else
		year = value
	end
	
	if year == '' or year == nil then
		return
	else
		year = tonumber(year)
	end
	
	if math.fmod(year, 20) == 1 or math.fmod(year, 20) == 10 or math.fmod(year, 20) == 5 or math.fmod(year, 20) == 15  or math.fmod(year, 200) == 100 then
		suffix = "eko"
	else
		suffix = "ko"
	end
	
	if linked then
		year = '[[' .. year .. ']]'
	end
	
	return year .. suffix
end

return p