انتقل إلى المحتوى

وحدة:HijriDate: الفرق بين النسختين

من ويكي الاحرار
لا ملخص تعديل
لا ملخص تعديل
سطر ١٦: سطر ١٦:
}
}


-- Julian Day from Gregorian
-- Tabular Islamic calendar
local function gregorian_to_jd(y, m, d)
local function gregorian_to_hijri(y, m, d)
if m <= 2 then
local jd = math.floor(
y = y - 1
(1461 * (y + 4800 + math.floor((m - 14) / 12))) / 4 +
m = m + 12
(367 * (m - 2 - 12 * math.floor((m - 14) / 12))) / 12 -
end
(3 * math.floor((y + 4900 + math.floor((m - 14) / 12)) / 100)) / 4 +
local A = math.floor(y / 100)
d - 32075
local B = 2 - A + math.floor(A / 4)
)
return math.floor(365.25 * (y + 4716))
+ math.floor(30.6001 * (m + 1))
+ d + B - 1524
end


-- Hijri calculation (Tabular Islamic calendar)
local l = jd - 1948440 + 10632
local function jd_to_hijri(jd)
local n = math.floor((l - 1) / 10631)
jd = math.floor(jd) + 0.5
l = l - 10631 * n + 354
local days = jd - 1948439.5
local j = (
local year = math.floor((30 * days + 10646) / 10631)
math.floor((10985 - l) / 5316) *
local month = math.min(
math.floor((50 * l) / 17719) +
12,
math.floor(l / 5670) *
math.ceil((days - 29 - hijri_to_jd(year, 1, 1)) / 29.5) + 1
math.floor((43 * l) / 15238)
)
)
local day = math.floor(jd - hijri_to_jd(year, month, 1)) + 1
l = l - (
math.floor((30 - j) / 15) *
math.floor((17719 * j) / 50) -
math.floor(j / 16) *
math.floor((15238 * j) / 43)
) + 29
 
local month = math.floor((24 * l) / 709)
local day = l - math.floor((709 * month) / 24)
local year = 30 * n + j - 30
 
return day, month, year
return day, month, year
end
function hijri_to_jd(y, m, d)
return d
+ math.ceil(29.5 * (m - 1))
+ (y - 1) * 354
+ math.floor((3 + 11 * y) / 30)
+ 1948439.5
end
end


function p.today()
function p.today()
local t = os.date("*t")
local t = os.date("*t")
local jd = gregorian_to_jd(t.year, t.month, t.day)
local d, m, y = gregorian_to_hijri(t.year, t.month, t.day)
local d, m, y = jd_to_hijri(jd)


if d < 1 or d > 30 then
if not months[m] then
return "خطأ في حساب التاريخ الهجري"
return "خطأ في حساب التاريخ الهجري"
end
end

مراجعة ١٣:٢٨، ١ يناير ٢٠٢٦

يمكن إنشاء صفحة توثيق الوحدة في وحدة:HijriDate/شرح

local p = {}

local months = {
	"محرم",
	"صفر",
	"ربيع الأول",
	"ربيع الآخر",
	"جمادى الأولى",
	"جمادى الآخرة",
	"رجب",
	"شعبان",
	"رمضان",
	"شوال",
	"ذو القعدة",
	"ذو الحجة"
}

-- Tabular Islamic calendar
local function gregorian_to_hijri(y, m, d)
	local jd = math.floor(
		(1461 * (y + 4800 + math.floor((m - 14) / 12))) / 4 +
		(367 * (m - 2 - 12 * math.floor((m - 14) / 12))) / 12 -
		(3 * math.floor((y + 4900 + math.floor((m - 14) / 12)) / 100)) / 4 +
		d - 32075
	)

	local l = jd - 1948440 + 10632
	local n = math.floor((l - 1) / 10631)
	l = l - 10631 * n + 354
	local j = (
		math.floor((10985 - l) / 5316) *
		math.floor((50 * l) / 17719) +
		math.floor(l / 5670) *
		math.floor((43 * l) / 15238)
	)
	l = l - (
		math.floor((30 - j) / 15) *
		math.floor((17719 * j) / 50) -
		math.floor(j / 16) *
		math.floor((15238 * j) / 43)
	) + 29

	local month = math.floor((24 * l) / 709)
	local day = l - math.floor((709 * month) / 24)
	local year = 30 * n + j - 30

	return day, month, year
end

function p.today()
	local t = os.date("*t")
	local d, m, y = gregorian_to_hijri(t.year, t.month, t.day)

	if not months[m] then
		return "خطأ في حساب التاريخ الهجري"
	end

	return d .. " " .. months[m] .. " " .. y .. " هـ"
end

return p