|
|
| سطر ١: |
سطر ١: |
| local p = {}
| |
|
| |
|
| local months = {
| |
| [1] = "محرم",
| |
| [2] = "صفر",
| |
| [3] = "ربيع الأول",
| |
| [4] = "ربيع الآخر",
| |
| [5] = "جمادى الأولى",
| |
| [6] = "جمادى الآخرة",
| |
| [7] = "رجب",
| |
| [8] = "شعبان",
| |
| [9] = "رمضان",
| |
| [10] = "شوال",
| |
| [11] = "ذو القعدة",
| |
| [12] = "ذو الحجة"
| |
| }
| |
|
| |
| local function gregorian_to_jd(y, m, d)
| |
| if m < 3 then
| |
| y = y - 1
| |
| m = m + 12
| |
| end
| |
| local a = math.floor(y / 100)
| |
| 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
| |
|
| |
| local function hijri_to_jd(y, m, d)
| |
| return d
| |
| + math.ceil(29.5 * (m - 1))
| |
| + (y - 1) * 354
| |
| + math.floor((3 + 11 * y) / 30)
| |
| + 1948440
| |
| end
| |
|
| |
| local function jd_to_hijri(jd)
| |
| local days = jd - 1948440
| |
| local year = math.floor((30 * days + 10646) / 10631)
| |
| local month = math.min(12, math.ceil((days - 29) / 29.5) + 1)
| |
| local day = jd - hijri_to_jd(year, month, 1) + 1
| |
| return day, month, year
| |
| end
| |
|
| |
| function p.today()
| |
| local t = os.date("*t")
| |
| local jd = gregorian_to_jd(t.year, t.month, t.day)
| |
| local d, m, y = jd_to_hijri(jd)
| |
|
| |
| if not months[m] then
| |
| return "خطأ في حساب التاريخ الهجري"
| |
| end
| |
|
| |
| return d .. " " .. months[m] .. " " .. y .. " هـ"
| |
| end
| |
|
| |
| return p
| |
مراجعة ١٣:٢٧، ١ يناير ٢٠٢٦
يمكن إنشاء صفحة توثيق الوحدة في وحدة:HijriDate/شرح