#include <iostream>
#include <cmath>
// Dereceyi Radyana Çevir
double degToRad(double degree) {
return (M_PI / 180) * degree;
}
// Radyanı Dereceye Çevir
double radToDeg(double radian) {
return radian * (180 / M_PI);
}
// Bir değeri 0 ile 360 arasında tutar
double moreLess360(double value) {
while (value > 360 || value < 0) {
if (value > 360)
value -= 360;
else if (value < 0)
value += 360;
}
return value;
}
// Bir değeri 0 ile 24 arasında tutar
double moreLess24(double value) {
while (value > 24 || value < 0) {
if (value > 24)
value -= 24;
else if (value < 0)
value += 24;
}
return value;
}
// Ondalık saati Saat ve Dakikaya çevir
void doubleToHrMin(double number, int &hours, int &minutes) {
hours = static_cast<int>(floor(moreLess24(number)));
minutes = static_cast<int>(floor(moreLess24(number - hours) * 60));
}
// Namaz vakitlerini hesaplar
void calcPrayerTimes(int year, int month, int day,
double longitude, double latitude, int timeZone,
double fajrTwilight, double ishaTwilight,
double &fajrTime, double &sunRiseTime, double &zuhrTime,
double &asrTime, double &maghribTime, double &ishaTime) {
double D = (367 * year) - ((year + static_cast<int>((month + 9) / 12)) * 7 / 4) + ((275 * month / 9) + day - 730531.5);
double L = 280.461 + 0.9856474 * D;
L = moreLess360(L);
double M = 357.528 + 0.9856003 * D;
M = moreLess360(M);
double Lambda = L + 1.915 * sin(degToRad(M)) + 0.02 * sin(degToRad(2 * M));
Lambda = moreLess360(Lambda);
double Obliquity = 23.439 - 0.0000004 * D;
double Alpha = radToDeg(atan(cos(degToRad(Obliquity)) * tan(degToRad(Lambda))));
Alpha = moreLess360(Alpha);
Alpha = Alpha - (360 * static_cast<int>(Alpha / 360));
Alpha = Alpha + 90 * (floor(Lambda / 90) - floor(Alpha / 90));
double ST = 100.46 + 0.985647352 * D;
double Dec = radToDeg(asin(sin(degToRad(Obliquity)) * sin(degToRad(Lambda))));
double Durinal_Arc = radToDeg(acos((sin(degToRad(-0.8333)) - sin(degToRad(Dec)) * sin(degToRad(latitude))) / (cos(degToRad(Dec)) * cos(degToRad(latitude)))));
double Noon = Alpha - ST;
Noon = moreLess360(Noon);
double UT_Noon = Noon - longitude;
////////////////////////////////////////////
// Namaz Vakitlerinin Hesaplanması
//////////////////////////////////////////
// Temkin değerleri
double fajrTemkin = 0.0;
double sunriseTemkin = -7.0 / 60.0;
double zuhrTemkin = 4.0 / 60.0;
double asrTemkin = 4.0 / 60.0;
double maghribTemkin = 7.0 / 60.0;
double ishaTemkin = 0.0;
// Öğle vakti [yerel öğle]
zuhrTime = (UT_Noon / 15 + timeZone) + zuhrTemkin;
// İkindi vakti
double Asr_Alt = radToDeg(atan(1 + tan(degToRad(fabs(latitude - Dec)))));
double Asr_Arc = radToDeg(acos((sin(degToRad(90 - Asr_Alt)) - sin(degToRad(Dec)) * sin(degToRad(latitude))) / (cos(degToRad(Dec)) * cos(degToRad(latitude)))));
Asr_Arc = Asr_Arc / 15;
asrTime = (zuhrTime + Asr_Arc) + asrTemkin;
// Sabah vakti
sunRiseTime = (zuhrTime - (Durinal_Arc / 15)) + sunriseTemkin;
// Akşam vakti
maghribTime = (zuhrTime + (Durinal_Arc / 15)) + maghribTemkin;
double Esha_Arc = radToDeg(acos((sin(degToRad(ishaTwilight)) - sin(degToRad(Dec)) * sin(degToRad(latitude))) / (cos(degToRad(Dec)) * cos(degToRad(latitude)))));
ishaTime = (zuhrTime + (Esha_Arc / 15)) + ishaTemkin;
double Fajr_Arc = radToDeg(acos((sin(degToRad(fajrTwilight)) - sin(degToRad(Dec)) * sin(degToRad(latitude))) / (cos(degToRad(Dec)) * cos(degToRad(latitude)))));
fajrTime = (zuhrTime - (Fajr_Arc / 15)) + fajrTemkin;
return;
}
int main() {
double fajr, sunRise, zuhr, asr, maghrib, isha;
calcPrayerTimes(2024, 11, 12, 32.8597, 39.9334, 3, -19, -17,
fajr, sunRise, zuhr, asr, maghrib, isha);
int hours, minutes;
doubleToHrMin(fajr, hours, minutes);
std::cout << "Fajr: " << hours << ":" << minutes << std::endl;
doubleToHrMin(sunRise, hours, minutes);
std::cout << "Sunrise: " << hours << ":" << minutes << std::endl;
doubleToHrMin(zuhr, hours, minutes);
std::cout << "Zuhr: " << hours << ":" << minutes << std::endl;
doubleToHrMin(asr, hours, minutes);
std::cout << "Asr: " << hours << ":" << minutes << std::endl;
doubleToHrMin(maghrib, hours, minutes);
std::cout << "Maghrib: " << hours << ":" << minutes << std::endl;
doubleToHrMin(isha, hours, minutes);
std::cout << "Isha: " << hours << ":" << minutes << std::endl;
}