ai ile yapılan büyük güncelleme
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
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()) {
|
||||
const year = date.getFullYear();
|
||||
const month = date.getMonth() + 1;
|
||||
const day = date.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 { missed: 0, days: 0 };
|
||||
}
|
||||
|
||||
const diffTime = today - mukallafDate;
|
||||
const days = Math.floor(diffTime / (1000 * 60 * 60 * 24));
|
||||
const missed = days * 5;
|
||||
|
||||
return { missed, days, mukallafDate };
|
||||
}
|
||||
|
||||
export function getHijriAge(birthDate, mukallafAge = 15) {
|
||||
const birth = new Date(birthDate);
|
||||
const today = new Date();
|
||||
|
||||
const hijriBirth = gregorianToHijri(birth);
|
||||
const hijriToday = gregorianToHijri(today);
|
||||
|
||||
let age = hijriToday.year - hijriBirth.year;
|
||||
if (
|
||||
hijriToday.month < hijriBirth.month ||
|
||||
(hijriToday.month === hijriBirth.month && hijriToday.day < hijriBirth.day)
|
||||
) {
|
||||
age -= 1;
|
||||
}
|
||||
|
||||
return Math.max(0, age);
|
||||
}
|
||||
Reference in New Issue
Block a user