بو ماژول اوچون بلگه‌لر ماژول:Iranian calendar/بلگه صفحه‌سینده یارادیلا بیلینر

-- This module is under development.

-- Useful functions about Iranian calendar to be used in Persian Wikipedia
-- Written by Alireza Eskandarpour Shoferi (@AEsShoferi) in Lua
--
-- Distributed under the terms of the CC BY-SA 4.0

-- Load necessary modules
local library = require("Module:Iranian calendar/library")
local convertToFa = require("Module:Numeral converter").convert
local getArgs = require("Module:Arguments").getArgs

local p = {}

function p.Age(frame)
	local args = getArgs(frame, {trim=true, removeBlanks=true})
	-- Converts Persian numbers to English because of arithmetic expressions
	local firstSet = {year = tonumber(convertToFa("en",args[1])), month = tonumber(convertToFa("en",args[2])), day = tonumber(convertToFa("en",args[3]))}
	local secondSet = {year = tonumber(convertToFa("en",args[4])) or library.getCurrentJalaliYear(), month = tonumber(convertToFa("en",args[5])) or library.getCurrentJalaliMonth(), day = tonumber(convertToFa("en",args[6])) or library.getCurrentJalaliDay()}

	-- Following expression borrowed from [[:en:Template:Age]]
	return convertToFa("fa",(secondSet.year - firstSet.year) - (((tonumber(secondSet.month) < tonumber(firstSet.month) ) or secondSet.month == firstSet.month and tonumber(secondSet.day) < tonumber(firstSet.day) ) and 1 or 0) )
end

return p