Module:Year navigation

local getArgs = require("Module:Arguments").getArgs
local infobox = require("Module:Infobox")

local p = {}

function p._main(args)
	local year = tonumber(args[1])
	
	if year == 0 then
		return error("Year cannot be 0. There was no [[year 0]].")
	end
	
	local millennium
	
	if year > 2000 then
		millennium = "[[3rd millennium]]"
	elseif year > 1000 then
		millennium = "[[2nd millennium]]"
	elseif year > 0 then
		millennium = "[[1st millennium]]"
	else
		millennium = "[[1st millennium BC|1st millennium <small>BC</small>]]"
	end
	
	return infobox.infobox({
		label1 = "[[List of decades, centuries, and millennia|Millennium]]:",
		data1 = millennium
	})
end

function p.main(frame)
	local args = getArgs(frame)
	if not args[1] then
		args[1] = frame:getTitle()
	end
	
	return p._main(args)
end

return p