Closed CamilleScholtz closed 4 years ago
It seems like cosValue
in the Acos
function in trigonomity.go
has a value of -1.0705466758213495
, the golang manpage about math.Acos
says:
Special condition:
Acos(x) = NaN if x < -1 or x > 1
Fixed by adding math.Max(fl, -1)
to the Acos
function, though I have no idea if this throws the calculations off.
Is this package still being developed? Else I will switch over to an alternative.
Sorry for late response.
I've added a check to make sure the cos value only between -1 and 1. Fortunately it seems the calculations is still quite accurate, at least when compared with SalahTimes.
Sorry. I recheck your error report above and it seems the panic is happened when calculating Fajr time.
After further read, I found out that cos value of hour angle is < -1 for area with high latitude where sun never set. However, your latitude is not high enough to trigger this panic.
With that said, my fix above is only heal the symptom and not the root cause. I'll keep this issue open until I found out how to fix it.
Hi @onodera-punpun, I've fixed it :rocket: (as far I could check, at least)
After I relearn how to calculate the prayer times, I realized the algorithm that used on this package only worked on area with low latitude (below 48.5 degree from equator). Thanks to this, it failed in area with higher latitude where the sun does not go 18 degree below horizon on the summer.
Now this package allow users to specify method for calculating prayer times in higher latitude by setting field HighLatitudeMethod
in Calculator
. There are three methods for calculating times in area with high latitude but the most common one to use is angle-based which is the default in this package.
Unfortunately, I've had to change the API to simplify the code so you might need to upgrade your code. For example, now iqama time doesn't handled by this package anymore since it's simply adding duration to the prayer time.
With that said, here is the playground for the fixed version.
Thanks a lot!
Error log:
I have a feeling this is because something rounds to zero or something, which makes the decimal package return a panic.
Code that crashes (for me):
Slightly changing the Latitude to 51 for example fixes the crash, also the crash didn't happen last week.