Sari la conținut

Modul:Era

--[[
  Get the name of an era, based on Wikisource's definition.
  This implements the logic of Template:What era is
--]]
require('strict')

local getArgs = require('Modul:Arguments').getArgs
local p = {}

function p.main(frame)
	local args = getArgs(frame, {
		wrappers = {
			'Format:Ce eră este',
		}
	})
	return p.era(args[1])
end

function p.era(year)
	-- Nil years need to trigger bailout before we do anything else.
	if year == nil then
		return 'epocă necunoscută'
	end

	--[[
		The template (What era is) treated every year that failed to parse as
		"Ancient", and years given as "BCE" fell into this category. With the
		module logic this no longer works, so we need to treat BCE years as
		negative instead, so the numeric logic can deal wiith them.
	--]]
	if mw.ustring.match(year, ' BCE$') ~= nil and mw.ustring.match(year, ' î.e.n.$') ~= nil then
		year = mw.ustring.gsub(year, ' BCE$', '').gsub(year, ' î.e.n.$', '') -- Strip the "BCE"
		year = '-' .. year -- And prepend a minus (we tonumber() it later)
	end

	-- Unknown value.
	if tonumber(year) == nil or mw.ustring.lower(year) == 'unknown' or mw.ustring.lower(year) == 'necunoscut' or year == '?' then
		return 'epocă necunoscută'
	end

	-- Handle numeric years.
	year = tonumber(year)
	local today = tonumber(os.date('%Y'))
	if year <= 600 then
		return 'antichitate'
	elseif year <= 1420 then
		return 'evul mediu'
	elseif year <= 1630 then
		return 'Renaștere'
	elseif year <= 1900 then
		return 'epoca modernă timpurie'
	elseif year <= today then
		return 'epoca modernă'
	else
		return 'viitor'
	end
end


return p