genel olarak yapılan düzeltmeler
This commit is contained in:
+32
-13
@@ -2,24 +2,16 @@ export async function fetchPrayerTimes(cityName = "Edremit", lat, lon) {
|
||||
try {
|
||||
let url;
|
||||
if (lat !== undefined && lon !== undefined) {
|
||||
url =
|
||||
"https://api.aladhan.com/v1/timings?latitude=" +
|
||||
encodeURIComponent(lat) +
|
||||
"&longitude=" +
|
||||
encodeURIComponent(lon) +
|
||||
"&method=13";
|
||||
url = `https://api.aladhan.com/v1/timings?latitude=${encodeURIComponent(lat)}&longitude=${encodeURIComponent(lon)}&method=13`;
|
||||
} else {
|
||||
url =
|
||||
"https://api.aladhan.com/v1/timingsByCity?city=" +
|
||||
encodeURIComponent(cityName) +
|
||||
"&country=Turkey&method=2";
|
||||
url = `https://api.aladhan.com/v1/timingsByCity?city=${encodeURIComponent(cityName)}&country=Turkey&method=13`;
|
||||
}
|
||||
const res = await fetch(url);
|
||||
if (!res.ok) {
|
||||
throw new Error("Namaz vakitleri alınamadı");
|
||||
}
|
||||
if (!res.ok) throw new Error("Namaz vakitleri alınamadı");
|
||||
|
||||
const data = await res.json();
|
||||
const t = data.data.timings;
|
||||
|
||||
return {
|
||||
fajr: t.Fajr,
|
||||
sunrise: t.Sunrise,
|
||||
@@ -28,9 +20,36 @@ export async function fetchPrayerTimes(cityName = "Edremit", lat, lon) {
|
||||
maghrib: t.Maghrib,
|
||||
isha: t.Isha,
|
||||
imsak: t.Imsak,
|
||||
currentPrayer: getCurrentPrayer(t),
|
||||
};
|
||||
} catch (err) {
|
||||
console.error("Namaz vakti hatası:", err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function getCurrentPrayer(timings) {
|
||||
const now = new Date();
|
||||
const currentMinutes = now.getHours() * 60 + now.getMinutes();
|
||||
|
||||
const parseTime = (timeStr) => {
|
||||
const [h, m] = timeStr.split(":").map(Number);
|
||||
return h * 60 + m;
|
||||
};
|
||||
|
||||
const imsak = parseTime(timings.Imsak);
|
||||
const dhuhr = parseTime(timings.Dhuhr);
|
||||
const asr = parseTime(timings.Asr);
|
||||
const maghrib = parseTime(timings.Maghrib);
|
||||
const isha = parseTime(timings.Isha);
|
||||
|
||||
if (currentMinutes >= imsak && currentMinutes < dhuhr)
|
||||
return { name: "Sabah", key: "fajr" };
|
||||
if (currentMinutes >= dhuhr && currentMinutes < asr)
|
||||
return { name: "Öğle", key: "dhuhr" };
|
||||
if (currentMinutes >= asr && currentMinutes < maghrib)
|
||||
return { name: "İkindi", key: "asr" };
|
||||
if (currentMinutes >= maghrib && currentMinutes < isha)
|
||||
return { name: "Akşam", key: "maghrib" };
|
||||
return { name: "Yatsı", key: "isha" };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user