Documentația acestui modul poate fi creată la Modul:Anul/doc

local avrund = require('Modul:Matematică')._round
local roman = require('Modul:Roman')._main

local function ihr(s)
	if string.match(s, " î.Hr.") then
		return (tonumber(string.sub(s, 1, -7))*-1)+1
	else
		return tonumber(s)
	end
end

---- Before or after Christos
local function beafch(a, b, c, d)
	if ihr(a) + b <= 0 then
		return ((ihr(a) + b)*-1)+1 .. c
	else
		return ihr(a) + b .. d
	end
end

-- What century it is
local function secol(s)
	if avrund(s, -2) >= tonumber(s) then
		return avrund(s, -2)/100
	else
		return (avrund(s, -2)/100)+1
	end
end

-- What decade it is
local function deceniu(s)
	if avrund(s, -1) <= tonumber(s) then
		return avrund(s, -1)
	else
		return avrund(s, -1)-10
	end
end

local function convert_to_roman(s)
	sd = ihr(s)
	if sd <= 0 then sad = 1-sd else sad = sd end
	ss = tostring(sad)
	local t = roman({ss})
	if sd <= 0 then t = t .. " î.Hr." end
	return t
end
	
local p = {}

-- Print year
function p.an(frame)
	return beafch(frame.args[1], frame.args[2], " î.Hr.", "")
end

-- Print century
function p.secol(frame)
	local args = frame.args
	if string.sub(args[1], -17, -1) == " î.Hr." then
		return "Secolul " .. convert_to_roman(beafch(ihr(string.sub(args[1], 1, -17) .. " î.Hr."), args[2], " î.Hr.", " "))
	elseif string.sub(args[1], -11, -1) == ". secol" then
		return "Secolul " .. convert_to_roman(beafch(ihr(string.sub(args[1], 1, -11)), args[2], " î.Hr.", " "))
	else
		return "Secolul " .. convert_to_roman(beafch(secol(ihr(args[1])), args[2], " î.Hr.", " "))
	end
end

-- Print decade
function p.deceniu(frame)
	if tonumber(frame.args[1]) + tonumber(frame.args[2])*10 < 0 then
		return "Anii " .. deceniu(frame.args[1]) + (tonumber(frame.args[2])+1)*-10 .. " î.Hr."
	else
		return "Anii " .. deceniu(frame.args[1]) + tonumber(frame.args[2])*10
	end
end

return p