const HIJRI_MONTHS = [ "Muharrem", "Safer", "Rebiülevvel", "Rebiülahir", "Cemaziyelevvel", "Cemaziyelahir", "Receb", "Şaban", "Ramazan", "Şevval", "Zilkade", "Zilhicce", ]; const DAYS = [ "Pazar", "Pazartesi", "Salı", "Çarşamba", "Perşembe", "Cuma", "Cumartesi", ]; export function gregorianToHijri(date = new Date()) { // Türkiye coğrafi hizalaması ve Hilal takvimi için +2 gün adjustment const adjustment = 2; const adjustedDate = new Date( date.getTime() + adjustment * 24 * 60 * 60 * 1000, ); const year = adjustedDate.getFullYear(); const month = adjustedDate.getMonth() + 1; const day = adjustedDate.getDate(); let a = Math.floor((14 - month) / 12); let y = year + 4800 - a; let m = month + 12 * a - 3; let jdn = day + Math.floor((153 * m + 2) / 5) + 365 * y + Math.floor(y / 4) - Math.floor(y / 100) + Math.floor(y / 400) - 32045; let l = jdn - 1948440 + 10632; let n = Math.floor((l - 1) / 10631); l = l - 10631 * n + 354; let 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; let hijriMonth = Math.floor((24 * l) / 709); let hijriDay = l - Math.floor((709 * hijriMonth) / 24); let hijriYear = 30 * n + j - 30; if (hijriMonth > 12) { hijriMonth -= 12; hijriYear += 1; } const weekday = DAYS[date.getDay()]; return { year: hijriYear, month: hijriMonth, day: hijriDay, monthName: HIJRI_MONTHS[hijriMonth - 1], weekday, }; } export function calculateMissedPrayers(birthDate, gender, mukallafAge = 15) { const birth = new Date(birthDate); const today = new Date(); today.setHours(0, 0, 0, 0); const mukallafDate = new Date(birth); mukallafDate.setFullYear(mukallafDate.getFullYear() + mukallafAge); if (today <= mukallafDate) { return { fajr: 0, dhuhr: 0, asr: 0, maghrib: 0, isha: 0, vitr: 0, days: 0 }; } const diffTime = today - mukallafDate; const days = Math.floor(diffTime / (1000 * 60 * 60 * 24)); return { fajr: days, dhuhr: days, asr: days, maghrib: days, isha: days, vitr: days, days, }; } export function getHijriBirthDate(birthDate) { return gregorianToHijri(new Date(birthDate)); }