batoulapps / Adhan

High precision prayer time library
MIT License
331 stars 63 forks source link

How Can I get the closest best calculation for prayer times #35

Closed sabrefm1-zz closed 7 years ago

sabrefm1-zz commented 7 years ago

I am based in south africa, how can i configure the adjustments to give me the correct times or possibly the closest time to when the adhan goes off

i have this link http://www.muslim.co.za/salaahtimes

they are accurate but I am playing around with the code but I am not getting close. This is what I have

let cal = Calendar(identifier: Calendar.Identifier.gregorian) let date = cal.dateComponents([.year, .month, .day], from: Date()) let coordinates = Coordinates(latitude: -33.925, longitude: 18.430) //cape town var params = CalculationMethod.other.params params.madhab = .shafi

    if let prayers = PrayerTimes(coordinates: coordinates, date: date, calculationParameters: params) {
        let formatter = DateFormatter()
        formatter.timeStyle = .medium
        formatter.timeZone = TimeZone(identifier: "UTC+02:00")!
z3bi commented 7 years ago

This is still one of the more difficult problems to solve, knowing which method to use for a particular location. I have not yet found any definitive answers in this regard, so the Adhan library doesn't have a feature to tell you which calculation method to use, it just offers all of them.

To match the times listed on site, you should use the following parameters:

var params = CalculationMethod.karachi.params
params.highLatitudeRule = .seventhOfTheNight
params.madhab = .shafi
sabrefm1-zz commented 7 years ago

Thanks for the info. I will look into it

z3bi commented 7 years ago

Also, I recommend using the properly named timezone.

formatter.timeZone = TimeZone(identifier: "Africa/Johannesburg")!
sabrefm1-zz commented 7 years ago

Will do

sabrefm1-zz commented 7 years ago

thanks those settings comes very close. Asr and Magrieb is almost on par but Fajr and Eshaai seems to be around +-10min out. What do you suggest I can do to fine tune those two prayer times

z3bi commented 7 years ago

I don't see a 10 minute difference.

With the values I posted and the coordinates you provided, here are the prayer times:

fajr: 4:31:00 AM sunrise: 5:56:00 AM dhuhr: 12:58:00 PM asr: 4:42:00 PM maghrib: 7:58:00 PM isha: 9:24:00 PM

and the website you posted lists:

Fajr: 4:26 Thur: 13:00 Asr: 16:42 Maghrib: 20:02 Eshaai: 21:22

So fajr has a difference of 5 minutes and isha has a difference of 2 minutes.

It appears that the website you posted is considering the true twilight times of Cape Town to be too extreme and is using an approximation method to instead make them more reasonable. This is why you have to set the highLatitudeRule property to seventhOfTheNight. With approximations it's hard to figure out exactly how they are getting those exact times, but if you still feel that 5 minutes is too large a difference you can set the adjustments property with something like this:

params.adjustments = PrayerAdjustments(fajr: -5, sunrise: 0, dhuhr: 0, asr: 0, maghrib: 0, isha: -2)

However, its possible that these adjustments will be different for other dates.