Muslims are supposed to perform five prayers every day. Each prayer is given a certain prescribed time in which it must be performed.
To determine the exact time period for each prayer, we need to determine five points of time per a day. These times are defined in the table below:
| Time | Definition |
| Fajr | When the sky begins to lighten, some time before the sun itself appears. (Dawn) |
| Sunrise | The time at which the first part of the sun appears above the horizon. |
| Dhuhr | When the sun appears the highest in the sky during its journey from sunrise to sunset. |
| Asr | Performed after Dhuhr Namaaz |
| Sunset | The time at which the sun disappears below the horizon. |
| Maghrib | 10-12 minutes after the sunset. (We have set it as 12) |
| Isha | Performed after Maghrib Namaaz |
The above seven times can be calculated mathematically for any location if the latitude and longitude of the location are known.
There are two astronomical measures that are essential for computing prayer times. These two measures are the equation of time and the declination of the Sun.
The equation of time is the difference between time as read from a sundial and a clock. It results from an apparent irregular movement of the Sun caused by a combination of the obliquity of the Earth's rotation axis and the eccentricity of its orbit. The sundial can be ahead (fast) by as much as 16 min 33 s (around November 3) or fall behind by as much as 14 min 6 s (around February 12).
The declination of the Sun is the angle between the rays of the sun and the plane of the earth equator. The declination of the Sun changes continuously throughout the year. This is a consequence of the Earth's tilt, i.e. the difference in its rotational and revolutionary axes.
The above two astronomical measures can be obtained accurately from The Star Almanac, or can be calculated approximately. In PrayTime, we have used an algorithm from U.S. Naval Observatory that computes the Sun's angular coordinates to an accuracy of about 1 arcminute within two centuries of 2000. Details of this approximation algorithm can be found below.
d = jd - 2451545.0; // jd is the given Julian date g = 357.529 + 0.98560028* d; q = 280.459 + 0.98564736* d; L = q + 1.915* sin(g) + 0.020* sin(2*g); R = 1.00014 - 0.01671* cos(g) - 0.00014* cos(2*g); e = 23.439 - 0.00000036* d; RA = arctan2(cos(e)* sin(L), cos(L))/ 15; D = arcsin(sin(e)* sin(L)); // declination of the Sun EqT = q/15 - RA; // equation of time
To calculate the prayer times for a given location, we need to know the latitude (L) and the longitude (Lng) of the location, along with the local TimeZone for that location. We also obtain the equation of time (EqT) and the declination of the Sun (D) for a given date using the algorithm mentioned in the previous section.
Dhuhr (mid-day) can be calculated easily using the following formula:
The time difference between the mid-day and the time at which sun reaches an angle a below the horizon can be computed using the following formula:
Astronomical sunrise and sunset occur at a=0. However, due to the refraction of light by terrestrial atmosphere, actual sunrise appears slightly before astronomical sunrise and actual sunset occurs after astronomical sunset. Actual sunrise and sunset can be computed using the following formulas:
There are differing opinions on what angle to use to calculate Fajr and Isha. The following table shows several conventions for calculating Fajr and Isha currently in use in various countries:
| Convention | Fajr Angle |
| Shia Ithna Ashari (Jafari) | 16 |
| University of Islamic Sciences, Karachi | 18 |
| Islamic Society of North America (ISNA) | 15 |
| Muslim World League (MWL) | 18 |
| Umm al-Qura, Makkah | 19 |
| Egyptian General Authority of Survey | 19.5 |
For example, according to Shia's convention, Fajr = Dhuhr - T(16)
In the Sunni's point of view, the time for Maghrib prayer begins once the Sun has completely set beneath the horizon (i.e., Maghrib = Sunset). In the Shia's view, however, the obligatory precaution is that as long as the redness in the eastern sky appearing after sunset has not passed overhead, Maghrib prayer should not be performed. It is usually taken into consideration by assuming a twilight angle of 4 for Maghrib, i.e., Maghrib = Dhuhr + T(4).
We add 12 minutes after Sunset and calculate Fajr at an angle of 16.7
In locations at higher latitude, twilight may persist throughout the night during some months of the year. In these abnormal periods, the determination of Fajr and Isha is not possible using the usual formulas mentioned in the previous section. To overcome this problem, several solutions have been proposed, three of which are described below.