ماڈیول:FarsiDate
Appearance
Documentation for this module may be created at ماڈیول:FarsiDate/doc
local getArgs = require('Module:Arguments').getArgs
local numConv = require('Module:Numeral converter').convert
local p = {}
local _solarMonths = {'فروردین ', 'اردیبهشت ', 'خرداد ', 'تیر ', 'مرداد ', 'شهریور ', 'مهر ', 'آبان ', 'آذر ', 'دی ', 'بهمن ', 'اسفند '}
local _gregorianMonths = {'جنوری ', 'فروری ', 'مارچ ', 'اپریل ', 'مئی ', 'جون ', 'جولائی ', 'اگست ', 'ستمبر ', 'اکتوبر ', 'نومبر ', 'دسمبر '}
local _solar = {["solar"] = true, ["خورشیدی"] = true}
function p.main(frame)
local args = getArgs(frame, {frameOnly=true})
return p.dateString(args[1], args[2], args[3], args[4])
end
function p.dateString(year, month, day, calendar)
-- Main module code goes here.
if _solar[calendar] then
months = _solarMonths
else
months = _gregorianMonths
end
local function toString()
if not month then
return numConv('fa', year)
elseif not day then
return months[tonumber(numConv('en', month))] .. numConv('fa', year)
else
return string.gsub(numConv('fa', day), '^۰', '') .. ' ' .. months[tonumber(numConv('en', month))] .. numConv('fa', year)
end
end
local success, result = pcall(toString)
if success then
return result
else
return '<span class="error">تاریخ ورودی نامعتبر است</span>'
end
end
return p