پرش به محتوا

پودمان:Date category

از ویکی‌خبر، مرجع خبری آزاد
نماد توضیحات توضیحات پودمان[ایجاد]
local p = {}

p.date = require("Module:Date")

p.gregorian_months = {"ژانویه","فوریه","مارس","آوریل","مه","ژوئن","ژوئیه","اوت","سپتامبر","اکتبر","نوامبر","دسامبر"}
p.solar_months = {"فروردین","خرداد","اردیبهشت","تیر","مرداد","شهریور","مهر","آبان","آذر","دی","بهمن","اسفند"}
p.nums = {["۰"]="0",["۱"]="1",["۲"]="2",["۳"]="3",["۴"]="4",["۵"]="5",["۶"]="6",["۷"]="7",["۸"]="8",["۹"]="9"}


function p.convert_numbers_to_en(txt)
	txt = tostring(txt)
	for k, v in pairs(p.nums) do
		txt = mw.ustring.gsub(txt,k,v)
	end
	return txt
end

function p.convert_numbers_to_fa(txt)
	txt = tostring(txt)
	for k, v in pairs(p.nums) do
		txt = mw.ustring.gsub(txt,v,k)
	end
	return txt
end

function p.gregorian_day_month_year(frame)
	local input = frame.args[1]
	local out = ''
	local xday, xmonth, xyear = input:match("(%S+) (%S+) (%S+)")
	if xday ~= nil and xmonth ~= nil and xyear ~= nil then
		xday = p.convert_numbers_to_en(xday)
		xyear = p.convert_numbers_to_en(xyear)
		if pcall(math.floor,xday) and pcall(math.floor,xyear) then
			xday = math.floor(xday)
			xyear = math.floor(xyear)
			for i,mname in pairs(p.gregorian_months) do
				if xmonth == mname then
					xmonth = i
					break
				end
			end
			local data = {year = xyear, month = xmonth, day = xday, hour = 0, min = 0, sec = 0}
			if pcall(os.time,data) and pcall(os.date,'%Y %m %d',timestamp) then
				local timestamp = os.time(data)
				local pdate = mw.text.split(os.date('%Y %m %d',timestamp-86400)," ")
				local cdate = mw.text.split(os.date('%Y %m %d',timestamp)," ")
				local ndate = mw.text.split(os.date('%Y %m %d',timestamp+86400)," ")
				
				local pyear = math.floor(pdate[1])
				local pmonth = math.floor(pdate[2])
				local pday = math.floor(pdate[3])
				
				pday = p.convert_numbers_to_fa(pday)
				pmonth = p.gregorian_months[pmonth]
				pyear = p.convert_numbers_to_fa(pyear)
			
				local cyear = math.floor(cdate[1])
				local cmonth = math.floor(cdate[2])
				local cday = math.floor(cdate[3])
				
				cday = p.convert_numbers_to_fa(cday)
				cmonth = p.gregorian_months[cmonth]
				cyear = p.convert_numbers_to_fa(cyear)
				
				local nyear = math.floor(ndate[1])
				local nmonth = math.floor(ndate[2])
				local nday = math.floor(ndate[3])
				
				nday = p.convert_numbers_to_fa(nday)
				nmonth = p.gregorian_months[nmonth]
				nyear = p.convert_numbers_to_fa(nyear)
				
				out = out .. '<div style="background-color: #e1f1f5; padding: 5px; width: 95%; border-radius: 10px; border: 1px solid #eddddd; margin-right: auto; margin-left: auto;"><table style="width: 100%;"><tr>'
					out = out .. '<td style="text-align: right;">'
						out = out .. '[[:رده:' .. pday .. ' ' .. pmonth .. ' ' .. pyear .. '|→ ' .. pday .. ' ' .. pmonth .. ' ' .. pyear .. ']]'
					out = out .. '</td>'
					out = out .. '<td style="text-align: left;">'
						out = out .. '[[:رده:' .. nday .. ' ' .. nmonth .. ' ' .. nyear .. '|' .. nday .. ' ' .. nmonth .. ' ' .. nyear .. ' ←]]'
					out = out .. '</td>'
				out = out .. '</tr></table></div>'
				
				out = out .. '[[رده:' .. cmonth .. ' ' .. cyear .. ']][[رده:' .. cday .. ' ' .. cmonth .. ']]'
			end
		end
	end
	return out
end

function p.gregorian_day_month(frame)
	local input = frame.args[1]
	local out = ''
	local xday, xmonth = input:match("(%S+) (%S+)")
	if xday ~= nil and xmonth ~= nil then
		xday = p.convert_numbers_to_en(xday)
		if pcall(math.floor,xday) then
			xday = math.floor(xday)
			for i,mname in pairs(p.gregorian_months) do
				if xmonth == mname then
					xmonth = i
					break
				end
			end
			local data = {year = 0, month = xmonth, day = xday, hour = 0, min = 0, sec = 0}
			if pcall(os.time,data) and pcall(os.date,'%m %d',timestamp) then
				local timestamp = os.time(data)
				local pdate = mw.text.split(os.date('%m %d',timestamp-86400)," ")
				local cdate = mw.text.split(os.date('%m %d',timestamp)," ")
				local ndate = mw.text.split(os.date('%m %d',timestamp+86400)," ")
				
				local pmonth = math.floor(pdate[1])
				local pday = math.floor(pdate[2])
				
				pday = p.convert_numbers_to_fa(pday)
				pmonth = p.gregorian_months[pmonth]
			
				local cmonth = math.floor(cdate[1])
				local cday = math.floor(cdate[2])
				
				cday = p.convert_numbers_to_fa(cday)
				cmonth = p.gregorian_months[cmonth]
				
				local nmonth = math.floor(ndate[1])
				local nday = math.floor(ndate[2])
				
				nday = p.convert_numbers_to_fa(nday)
				nmonth = p.gregorian_months[nmonth]
				
				out = out .. '<div style="background-color: #e1f1f5; padding: 5px; width: 95%; border-radius: 10px; border: 1px solid #eddddd; margin-right: auto; margin-left: auto;"><table style="width: 100%;"><tr>'
					out = out .. '<td style="text-align: right;">'
						out = out .. '[[:رده:' .. pday .. ' ' .. pmonth .. '|→ ' .. pday .. ' ' .. pmonth .. ']]'
					out = out .. '</td>'
					out = out .. '<td style="text-align: left;">'
						out = out .. '[[:رده:' .. nday .. ' ' .. nmonth .. '|' .. nday .. ' ' .. nmonth .. ' ←]]'
					out = out .. '</td>'
				out = out .. '</tr></table></div>'
				
				out = out .. '[[رده:' .. cmonth .. ']]'
			end
		end
	end
	return out
end

function p.gregorian_month_year(frame)
	local input = frame.args[1]
	local out = ''
	local xmonth, xyear = input:match("(%S+) (%S+)")
	if xmonth ~= nil and xyear ~= nil then
		xyear = p.convert_numbers_to_en(xyear)
		if pcall(math.floor,xyear) then
			xyear = math.floor(xyear)
			for i,mname in pairs(p.gregorian_months) do
				if xmonth == mname then
					xmonth = i
					break
				end
			end
			local data = {year = xyear, month = xmonth, day = 15, hour = 0, min = 0, sec = 0}
			if pcall(os.time,data) and pcall(os.date,'%Y %m',timestamp) then
				local timestamp = os.time(data)
				local pdate = mw.text.split(os.date('%Y %m',timestamp-2592000)," ")
				local cdate = mw.text.split(os.date('%Y %m',timestamp)," ")
				local ndate = mw.text.split(os.date('%Y %m',timestamp+2592000)," ")
				
				local pyear = math.floor(pdate[1])
				local pmonth = math.floor(pdate[2])
				
				pmonth = p.gregorian_months[pmonth]
				pyear = p.convert_numbers_to_fa(pyear)
			
				local cyear = math.floor(cdate[1])
				local cmonth = math.floor(cdate[2])
				
				cmonth = p.gregorian_months[cmonth]
				cyear = p.convert_numbers_to_fa(cyear)
				
				local nyear = math.floor(ndate[1])
				local nmonth = math.floor(ndate[2])
				
				nmonth = p.gregorian_months[nmonth]
				nyear = p.convert_numbers_to_fa(nyear)
				
				out = out .. '<div style="background-color: #e1f1f5; padding: 5px; width: 95%; border-radius: 10px; border: 1px solid #eddddd; margin-right: auto; margin-left: auto;"><table style="width: 100%;"><tr>'
					out = out .. '<td style="text-align: right;">'
						out = out .. '[[:رده:' .. pmonth .. ' ' .. pyear .. '|→ ' .. pmonth .. ' ' .. pyear .. ']]'
					out = out .. '</td>'
					out = out .. '<td style="text-align: left;">'
						out = out .. '[[:رده:' .. nmonth .. ' ' .. nyear .. '|' .. nmonth .. ' ' .. nyear .. ' ←]]'
					out = out .. '</td>'
				out = out .. '</tr></table></div>'
				
				out = out .. '[[رده:' .. cmonth .. ']][[رده:' .. cyear .. ']]'
			end
		end
	end
	return out
end

function p.solar_day_month_year(frame)
	local input = frame.args[1]
	local out = ''
	local xday, xmonth, xyear = input:match("(%S+) (%S+) (%S+)")
	if xday ~= nil and xmonth ~= nil and xyear ~= nil then
		xday = p.convert_numbers_to_en(xday)
		xyear = p.convert_numbers_to_en(xyear)
		if pcall(math.floor,xday) and pcall(math.floor,xyear) then
			xday = math.floor(xday)
			xyear = math.floor(xyear)
			for i,mname in pairs(p.solar_months) do
				if xmonth == mname then
					xmonth = i
					break
				end
			end
			local res = p.date.solar_to_gregorian({xyear,xmonth,xday})
			local data = {year = res[1], month = res[2], day = res[3], hour = 0, min = 0, sec = 0}
			if pcall(os.time,data) and pcall(os.date,'%Y %m %d',timestamp) then
				local timestamp = os.time(data)
				local pdate = mw.text.split(os.date('%Y %m %d',timestamp-86400)," ")
				local cdate = mw.text.split(os.date('%Y %m %d',timestamp)," ")
				local ndate = mw.text.split(os.date('%Y %m %d',timestamp+86400)," ")
				
				pdate = p.date.gregorian_to_solar(math.floor(pdate[1]),math.floor(pdate[2]),math.floor(pdate[3]))
				
				local pyear = pdate[1]
				local pmonth = pdate[2]
				local pday = pdate[3]
				
				pday = p.convert_numbers_to_fa(pday)
				pmonth = p.solar_months[pmonth]
				pyear = p.convert_numbers_to_fa(pyear)
				
				cdate = p.date.gregorian_to_solar(math.floor(cdate[1]),math.floor(cdate[2]),math.floor(cdate[3]))
				
				local cyear = cdate[1]
				local cmonth = cdate[2]
				local cday = cdate[3]
				
				cday = p.convert_numbers_to_fa(cday)
				cmonth = p.solar_months[cmonth]
				cyear = p.convert_numbers_to_fa(cyear)
				
				ndate = p.date.gregorian_to_solar(math.floor(ndate[1]),math.floor(ndate[2]),math.floor(ndate[3]))
				
				local nyear = ndate[1]
				local nmonth = ndate[2]
				local nday = ndate[3]
				
				nday = p.convert_numbers_to_fa(nday)
				nmonth = p.solar_months[nmonth]
				nyear = p.convert_numbers_to_fa(nyear)
				
				out = out .. '<div style="background-color: #e1f1f5; padding: 5px; width: 95%; border-radius: 10px; border: 1px solid #eddddd; margin-right: auto; margin-left: auto;"><table style="width: 100%;"><tr>'
					out = out .. '<td style="text-align: right;">'
						out = out .. '[[:رده:' .. pday .. ' ' .. pmonth .. ' ' .. pyear .. '|→ ' .. pday .. ' ' .. pmonth .. ' ' .. pyear .. ']]'
					out = out .. '</td>'
					out = out .. '<td style="text-align: left;">'
						out = out .. '[[:رده:' .. nday .. ' ' .. nmonth .. ' ' .. nyear .. '|' .. nday .. ' ' .. nmonth .. ' ' .. nyear .. ' ←]]'
					out = out .. '</td>'
				out = out .. '</tr></table></div>'
				
				out = out .. '[[رده:' .. cmonth .. ' ' .. cyear .. ']][[رده:' .. cday .. ' ' .. cmonth .. ']]'
			end
		end
	end
	return out
end

function p.solar_day_month(frame)
	local input = frame.args[1]
	local out = ''
	local xday, xmonth = input:match("(%S+) (%S+)")
	if xday ~= nil and xmonth ~= nil then
		xday = p.convert_numbers_to_en(xday)
		if pcall(math.floor,xday) then
			xday = math.floor(xday)
			for i,mname in pairs(p.solar_months) do
				if xmonth == mname then
					xmonth = i
					break
				end
			end
			local res = p.date.solar_to_gregorian({979,xmonth,xday})
			local data = {year = res[1], month = res[2], day = res[3], hour = 0, min = 0, sec = 0}
			if pcall(os.time,data) and pcall(os.date,'%Y %m %d',timestamp) then
				local timestamp = os.time(data)
				local pdate = mw.text.split(os.date('%Y %m %d',timestamp-86400)," ")
				local cdate = mw.text.split(os.date('%Y %m %d',timestamp)," ")
				local ndate = mw.text.split(os.date('%Y %m %d',timestamp+86400)," ")
				
				pdate = p.date.gregorian_to_solar(math.floor(pdate[1]),math.floor(pdate[2]),math.floor(pdate[3]))
				
				local pyear = pdate[1]
				local pmonth = pdate[2]
				local pday = pdate[3]
				
				pday = p.convert_numbers_to_fa(pday)
				pmonth = p.solar_months[pmonth]
				pyear = p.convert_numbers_to_fa(pyear)
				
				cdate = p.date.gregorian_to_solar(math.floor(cdate[1]),math.floor(cdate[2]),math.floor(cdate[3]))
				
				local cyear = cdate[1]
				local cmonth = cdate[2]
				local cday = cdate[3]
				
				cday = p.convert_numbers_to_fa(cday)
				cmonth = p.solar_months[cmonth]
				cyear = p.convert_numbers_to_fa(cyear)
				
				ndate = p.date.gregorian_to_solar(math.floor(ndate[1]),math.floor(ndate[2]),math.floor(ndate[3]))
				
				local nyear = ndate[1]
				local nmonth = ndate[2]
				local nday = ndate[3]
				
				nday = p.convert_numbers_to_fa(nday)
				nmonth = p.solar_months[nmonth]
				nyear = p.convert_numbers_to_fa(nyear)
				
				out = out .. '<div style="background-color: #e1f1f5; padding: 5px; width: 95%; border-radius: 10px; border: 1px solid #eddddd; margin-right: auto; margin-left: auto;"><table style="width: 100%;"><tr>'
					out = out .. '<td style="text-align: right;">'
						out = out .. '[[:رده:' .. pday .. ' ' .. pmonth .. '|→ ' .. pday .. ' ' .. pmonth .. ']]'
					out = out .. '</td>'
					out = out .. '<td style="text-align: left;">'
						out = out .. '[[:رده:' .. nday .. ' ' .. nmonth .. '|' .. nday .. ' ' .. nmonth .. ' ←]]'
					out = out .. '</td>'
				out = out .. '</tr></table></div>'
				
				out = out .. '[[رده:' .. cmonth .. ']]'
			end
		end
	end
	return out
end

function p.solar_month_year(frame)
	local input = frame.args[1]
	local out = ''
	local xmonth, xyear = input:match("(%S+) (%S+)")
	if xmonth ~= nil and xyear ~= nil then
		xyear = p.convert_numbers_to_en(xyear)
		if pcall(math.floor,xyear) then
			xyear = math.floor(xyear)
			for i,mname in pairs(p.solar_months) do
				if xmonth == mname then
					xmonth = i
					break
				end
			end
			local res = p.date.solar_to_gregorian({xyear,xmonth,15})
			local data = {year = res[1], month = res[2], day = res[3], hour = 0, min = 0, sec = 0}
			if pcall(os.time,data) and pcall(os.date,'%Y %m %d',timestamp) then
				local timestamp = os.time(data)
				local pdate = mw.text.split(os.date('%Y %m %d',timestamp-2592000)," ")
				local cdate = mw.text.split(os.date('%Y %m %d',timestamp)," ")
				local ndate = mw.text.split(os.date('%Y %m %d',timestamp+2592000)," ")
				
				pdate = p.date.gregorian_to_solar(math.floor(pdate[1]),math.floor(pdate[2]),math.floor(pdate[3]))
				
				local pyear = pdate[1]
				local pmonth = pdate[2]
				local pday = pdate[3]
				
				pday = p.convert_numbers_to_fa(pday)
				pmonth = p.solar_months[pmonth]
				pyear = p.convert_numbers_to_fa(pyear)
				
				cdate = p.date.gregorian_to_solar(math.floor(cdate[1]),math.floor(cdate[2]),math.floor(cdate[3]))
				
				local cyear = cdate[1]
				local cmonth = cdate[2]
				local cday = cdate[3]
				
				cday = p.convert_numbers_to_fa(cday)
				cmonth = p.solar_months[cmonth]
				cyear = p.convert_numbers_to_fa(cyear)
				
				ndate = p.date.gregorian_to_solar(math.floor(ndate[1]),math.floor(ndate[2]),math.floor(ndate[3]))
				
				local nyear = ndate[1]
				local nmonth = ndate[2]
				local nday = ndate[3]
				
				nday = p.convert_numbers_to_fa(nday)
				nmonth = p.solar_months[nmonth]
				nyear = p.convert_numbers_to_fa(nyear)
				
				out = out .. '<div style="background-color: #e1f1f5; padding: 5px; width: 95%; border-radius: 10px; border: 1px solid #eddddd; margin-right: auto; margin-left: auto;"><table style="width: 100%;"><tr>'
					out = out .. '<td style="text-align: right;">'
						out = out .. '[[:رده:' .. pmonth .. ' ' .. pyear .. '|→ ' .. pmonth .. ' ' .. pyear .. ']]'
					out = out .. '</td>'
					out = out .. '<td style="text-align: left;">'
						out = out .. '[[:رده:' .. nmonth .. ' ' .. nyear .. '|' .. nmonth .. ' ' .. nyear .. ' ←]]'
					out = out .. '</td>'
				out = out .. '</tr></table></div>'
				
				out = out .. '[[رده:' .. cmonth .. ']][[رده:' .. cyear .. ']]'
			end
		end
	end
	return out
end

function p.solar_month(frame)
	local xmonth = frame.args[1]
	for i,mname in pairs(p.solar_months) do
		if xmonth == mname then
			xmonth = i
			break
		end
	end
	xmonth = xmonth - 1
	local pmonth = p.solar_months[((xmonth - 1) % 12) + 1]
	local nmonth = p.solar_months[((xmonth + 1) % 12) + 1]
	local out = ''
	out = out .. '<div style="background-color: #e1f1f5; padding: 5px; width: 95%; border-radius: 10px; border: 1px solid #eddddd; margin-right: auto; margin-left: auto;"><table style="width: 100%;"><tr>'
		out = out .. '<td style="text-align: right;">'
			out = out .. '[[:رده:' .. pmonth .. '|→ ' .. pmonth  .. ']]'
		out = out .. '</td>'
		out = out .. '<td style="text-align: left;">'
			out = out .. '[[:رده:' .. nmonth .. '|' .. nmonth .. ' ←]]'
		out = out .. '</td>'
	out = out .. '</tr></table></div>'
	out = out .. '[[رده:اخبار بر پایه تاریخ خورشیدی]]'
	return out
end

function p.gregorian_month(frame)
	local xmonth = frame.args[1]
	for i,mname in pairs(p.gregorian_months) do
		if xmonth == mname then
			xmonth = i
			break
		end
	end
	xmonth = xmonth - 1
	local pmonth = p.gregorian_months[((xmonth - 1) % 12) + 1]
	local nmonth = p.gregorian_months[((xmonth + 1) % 12) + 1]
	local out = ''
	out = out .. '<div style="background-color: #e1f1f5; padding: 5px; width: 95%; border-radius: 10px; border: 1px solid #eddddd; margin-right: auto; margin-left: auto;"><table style="width: 100%;"><tr>'
		out = out .. '<td style="text-align: right;">'
			out = out .. '[[:رده:' .. pmonth .. '|→ ' .. pmonth  .. ']]'
		out = out .. '</td>'
		out = out .. '<td style="text-align: left;">'
			out = out .. '[[:رده:' .. nmonth .. '|' .. nmonth .. ' ←]]'
		out = out .. '</td>'
	out = out .. '</tr></table></div>'
	out = out .. '[[رده:اخبار بر پایه تاریخ میلادی]]'
	return out
end

function p.solar_year(frame)
	local xyear = math.floor(p.convert_numbers_to_en(frame.args[1]))
	local pyear = p.convert_numbers_to_fa(xyear - 1)
	local nyear = p.convert_numbers_to_fa(xyear + 1)
	local out = ''
	out = out .. '<div style="background-color: #e1f1f5; padding: 5px; width: 95%; border-radius: 10px; border: 1px solid #eddddd; margin-right: auto; margin-left: auto;"><table style="width: 100%;"><tr>'
		out = out .. '<td style="text-align: right;">'
			out = out .. '[[:رده:' .. pyear .. '|→ ' .. pyear .. ']]'
		out = out .. '</td>'
		out = out .. '<td style="text-align: left;">'
			out = out .. '[[:رده:' .. nyear .. '|' .. nyear .. ' ←]]'
		out = out .. '</td>'
	out = out .. '</tr></table></div>'
	out = out .. '[[رده:اخبار بر پایه تاریخ]]'
	return out
end

function p.gregorian_year(frame)
	local xyear = math.floor(p.convert_numbers_to_en(frame.args[1]))
	local pyear = p.convert_numbers_to_fa(xyear - 1)
	local nyear = p.convert_numbers_to_fa(xyear + 1)
	local out = ''
	out = out .. '<div style="background-color: #e1f1f5; padding: 5px; width: 95%; border-radius: 10px; border: 1px solid #eddddd; margin-right: auto; margin-left: auto;"><table style="width: 100%;"><tr>'
		out = out .. '<td style="text-align: right;">'
			out = out .. '[[:رده:' .. pyear .. '|→ ' .. pyear .. ']]'
		out = out .. '</td>'
		out = out .. '<td style="text-align: left;">'
			out = out .. '[[:رده:' .. nyear .. '|' .. nyear .. ' ←]]'
		out = out .. '</td>'
	out = out .. '</tr></table></div>'
	out = out .. '[[رده:اخبار بر پایه تاریخ]]'
	return out
end

return p