پرش به محتوا

پودمان:Era

از ویکی‌نبشته

توضیحات این پودمان می‌تواند در پودمان:Era/توضیحات قرار گیرد.

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

local numConv = require('پودمان:Number Converter').convert
local getArgs = require('Module:Arguments').getArgs
local p = {}

function p.main(frame)
	local args = getArgs(frame, {
		wrappers = {
			'Template:What era is',
		}
	})
	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 'دوره نامعلوم'
	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 loonger works, so we need to treat BCE years as
		negative instead, so the numeric logic can deal wiith them.
	--]]
	if mw.ustring.match(year, ' %(پیش از میلاد%)$') ~= nil then
		year = mw.ustring.gsub(year, ' %(پیش از میلاد%)$', '') -- Strip the "BCE"
		year = '-' .. year -- And prepend a minus (we tonumber() it later)
	end

	-- Unknown value.
	if tonumber(numConv('en', year)) == nil or mw.ustring.lower(year) == 'نامعلوم' or year == '?' or year == '؟' then
		return 'دوره نامعلوم'
	end

	-- Handle numeric years.
	year = tonumber(numConv('em', year))
	local today = tonumber(os.date('%Y'))
	if year <= 600 then
		return 'باستان'
	elseif year <= 1420 then
		return 'دوران میانه'
	elseif year <= 1630 then
		return 'رنسانس'
	elseif year <= 1900 then
		return 'عصر جدید اولیه'
	elseif year <= today then
		return 'دوران مدرن'
	else
		return 'آینده'
	end
end


return p