وحدة:HijriDate: الفرق بين النسختين
المظهر
لا ملخص تعديل |
لا ملخص تعديل |
||
| سطر ١٦: | سطر ١٦: | ||
} | } | ||
-- | -- Tabular Islamic calendar | ||
local function | local function gregorian_to_hijri(y, m, d) | ||
local jd = math.floor( | |||
y | (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 | local n = math.floor((l - 1) / 10631) | ||
l = l - 10631 * n + 354 | |||
local j = ( | |||
local | math.floor((10985 - l) / 5316) * | ||
math.floor((50 * l) / 17719) + | |||
math.floor(l / 5670) * | |||
math. | math.floor((43 * l) / 15238) | ||
) | ) | ||
local day = math.floor( | 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 | end | ||
function p.today() | function p.today() | ||
local t = os.date("*t") | local t = os.date("*t") | ||
local | local d, m, y = gregorian_to_hijri(t.year, t.month, t.day) | ||
if | 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