پودمان:Iranian calendar
پرش به ناوبری
پرش به جستجو
توضیحات این پودمان میتواند در پودمان: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 convertNumber = require("Module:Numeral converter").convert
local getArgs = require("Module:Arguments").getArgs
-- function form [[Module:Age#L-113]]
local function stripToNil(text)
-- If text is a string, return its trimmed content, or nil if empty.
-- Otherwise return text (which may, for example, be nil).
if type(text) == 'string' then
text = mw.ustring.match(text, '(%S.-)%s*$')
end
return text
end
local p = {}
function p.Age(frame)
local args = getArgs(frame, {trim=true, removeBlanks=true})
-- Converts Persian numbers to English because of arithmetic expressions
local birthSet = {year = tonumber(convertNumber("en", args[1])), month = tonumber(convertNumber("en", args[2])), day = tonumber(convertNumber("en", args[3]))}
local deathSet = {year = tonumber(convertNumber("en", args[4])) or library.getCurrentJalaliYear(), month = tonumber(convertNumber("en", args[5])) or library.getCurrentJalaliMonth(), day = tonumber(convertNumber("en", args[6])) or library.getCurrentJalaliDay()}
if not stripToNil(birthSet.month) and not stripToNil(birthSet.day) then
-- If day and month of birth is not provided,
-- then calculate the age using only the birth-year
-- In this case, month and day of the death are not considered for calculation
-- outputs a range; e.g. 54–55
return convertNumber("fa", (deathSet.year - birthSet.year) - 1) .. '–' .. convertNumber("fa", (deathSet.year - birthSet.year))
else
-- Following expression borrowed from [[:en:Template:Age]]
return convertNumber("fa", (deathSet.year - birthSet.year) - (((tonumber(deathSet.month) < tonumber(birthSet.month) ) or deathSet.month == birthSet.month and tonumber(deathSet.day) < tonumber(birthSet.day) ) and 1 or 0) )
end
end
return p