Skip to main content

Prayer times, part 7: the far north, the clock, and the whole program

· 47 min read
Rizki Rakasiwi
Muslimtify maintainer

Six parts in, the five prayer times are one formula asked five ways, and a table of what each country adds on top. This last part is about the cases where that is not enough.

Two of them are about the sky: places where the sun never gets 18° below the horizon, and places where it never sets at all. One is about the clock, which is a government decision and not an astronomical one, and gets more people's prayer times wrong than any angle ever did. Then the whole program, in one file, checked against the production library for every day of a year.

This is part 7 of a series, and the last

Parts 1 to 6 built the five prayer times from the texts up and walked through the national standards. This part closes the gaps and assembles the program. The full series is under the prayer time calculation tag.

When the sun does not get there​

Run the program from part 6 for London on 21 June and the Fajr and Isha cells come back empty. The formula is not broken. At latitude 51.5° in midsummer the sun only sinks to about 15° below the horizon at midnight. It never reaches 18°, so there is no moment that satisfies the Muslim World League's definition of Fajr, and hour_angle says so by returning nothing.

How often this happens depends on how far north you are. The picture to hold in mind is the sun's altitude at solar midnight, the lowest point of its daily circle. It is simply your latitude plus the declination, minus 90°.

For Jakarta the question never arises. For London the sun stays above 18° down from 23 May to 21 July, sixty days. For Oslo it is April to August. For Tromsø, inside the Arctic Circle, the sun does not set at all for two months, and then in winter does not rise for two months, so there is no sunrise, no Maghrib, and no shadow for Asr either.

-90°-75°-60°-45°-30°-15°0°JanFebMarAprMayJunJulAugSepOctNovDecthe sun's altitude at solar midnight−18°: above this line there is no real Fajr or Isha at 18°horizon: above this line the sun never setsJakarta 6° SLondon 51.5° NOslo 59.9° NTromsø 69.6° N
How low the sun gets at midnight. Below the dashed line the 18° prayers exist. London crosses it from late May to mid July, Oslo from April to August, and in Tromsø the sun does not set at all for two months. In Jakarta the question never arises.

What the texts say​

This is not a modern problem invented by astronomers. The Companions asked the Prophet ﷺ about a day that would last a year, in the hadith of the Dajjal, and he answered:

لَا، اقْدُرُوا لَهُ قَدْرَهُ

"No. Estimate for it its measure." (Sahih Muslim 2937)

That one word, uqduru, estimate, is the textual basis every authority leans on for the far north. When the sign in the sky does not come, you do not abandon the prayer, you estimate its time by a measure. The disagreement is about which measure.

The three measures​

Three rules are in common use, and all three take the length of the real night, from sunset to sunrise, and place Fajr and Isha some fraction of the way into it.

The middle of the night rule puts Fajr and Isha both at the midpoint, so there is always a night that ends and a night that begins. The one seventh rule puts Isha one seventh of the night after sunset and Fajr one seventh before sunrise. The angle-based rule, which praytimes.org popularized and most libraries now use, takes the method's own angle as the fraction: for an 18° method, Fajr is 18/60 of the night before sunrise. The idea is that on a normal night the sun covers roughly 60° of its circle between sunset and sunrise, so 18° of twilight is 18/60 of the night, and the rule carries that proportion into nights where the real angle is out of reach.

The angle-based rule has a practical virtue: on the last day before the gap and the first day after, the real time and the substitute are nearly the same, so the timetable does not jump. libmuslim uses it for every method whenever a real night exists, because when its authors checked the Muslim World League's own published London tables for June and July 2026, the angle-based rule reproduced them to within a minute and the alternatives did not. Whoever computes those tables uses this rule, so this is what "the MWL method" means in practice at high latitudes.

01:0002:0003:0004:0005:0006:0007:0008:0009:00JanFebMarAprMayJunJulAugSepOctNovDecFajr in London (Muslim World League, 18°), on the civil clock with summer timesunriseclocks forwardclocks back23 May to 21 Jul: the sun never reaches 18°dashed: 18/60 of the night before sunrise
London's Fajr through the year under the Muslim World League method. For 60 days in summer there is no moment when the sun is 18° down, and the substitute places Fajr at 18/60 of the night before sunrise. The join is smooth, which is the point of the rule. The two one-hour steps in March and October are not the sun: they are British Summer Time.

Inside the polar circle​

When there is no sunset there is no night to take a fraction of, and all three rules fall silent. Some apps then borrow a day from a lower latitude: compute the whole timetable as if the city sat at 45° (or, for the Moonsighting Committee, 60°) on the same meridian, and use that. libmuslim does this for the polar case, which is why it prints a full Tromsø timetable in June. The code in this series does not. For Tromsø on 21 June it prints Dhuhr and Asr, which exist, and leaves the rest blank.

Both answers are defensible, and that is the point. Borrowing a latitude is a fatwa, not a calculation, and the scholars who have addressed it do not agree. A timetable that prints a borrowed time without saying so is claiming more than it knows. If you ever ship this code to users above 66°, mark the substituted times as substituted. The hadith says estimate, it does not say pretend.

Clocks are political too​

Everything in this series has taken a timezone number: 7 for Jakarta, 1 for London in June. That number is not astronomy. It is whatever the government says the clock reads, and governments change their minds.

Egypt is the example to remember. Cairo is UTC+2 in winter and, since daylight saving time was reinstated in 2023, UTC+3 from the last Friday of April to the last Thursday of October. In 2026 that is 24 April to 29 October. Run the program for Cairo on 17 October with the Egyptian method:

Cairo, 17 October 2026, egypt fajr dhuhr asr maghrib isha
with UTC+3 (summer time, correct) 05:32 12:41 15:56 18:23 19:40
with UTC+2 (winter time, wrong) 04:32 11:41 14:56 17:23 18:40

The sun did the same thing in both rows. Pass the wrong offset and every prayer is an hour early, and a reader fasting in Ramadan would break their fast with the sun still up. There is no astronomical check that can catch this, because the astronomy is identical. The only defence is to get the offset from a source that knows the rules: the operating system's timezone database, which tracks every country's DST decisions and is updated several times a year. libmuslim ships a timezone.h for exactly this reason, and Muslimtify asks the system rather than the user.

Indonesia makes it easy, with three fixed zones and no summer time. Britain, most of Europe, the United States and Egypt make it hard. The London figure above is drawn on the civil clock, and the two one-hour steps in it, in March and October, are not the sun moving. They are the clocks.

One more clock problem hides in the Oslo row of the table below. Isha comes out at 00:12. That is twelve minutes past midnight on 22 June, but it is the Isha of 21 June, and a timetable that prints it in the 22 June row has moved it by a day. Times in this series are hours from the midnight that starts the date you asked for, so a value above 24 means "after midnight, still tonight". Keep it that way until the moment you print.

The code​

This replaces prayer_times from part 6. The only change is the substitute: when Fajr or Isha comes back empty and a real night exists, place it at the method's angle as a share of the night. When there is no night, leave it empty.

def prayer_times(year, month, day, latitude, longitude, timezone, method, shadow_factor=1):
"""The five prayer times as local clock hours, with the method's offsets, precaution
and the high-latitude substitute applied. None means the time does not exist."""
jd = julian_day(year, month, day)
sunrise = sun_event(jd, latitude, longitude, timezone, SUNRISE_ALTITUDE, -1)
sunset = sun_event(jd, latitude, longitude, timezone, SUNRISE_ALTITUDE, +1)
night = None if sunrise is None or sunset is None else (24 - sunset) + sunrise # hours of darkness
maghrib = None if sunset is None else sunset + method["maghrib"] / 60

fajr = sun_event(jd, latitude, longitude, timezone, -method["fajr"], -1)
if fajr is None and night is not None:
fajr = sunrise - method["fajr"] / 60 * night # angle-based substitute: the angle as a share of the night
if method["interval"]:
isha = None if maghrib is None else maghrib + method["interval"] / 60
else:
isha = sun_event(jd, latitude, longitude, timezone, -method["isha"], +1)
if isha is None and night is not None:
isha = maghrib + method["isha"] / 60 * night

times = {
"fajr": fajr,
"dhuhr": solar_noon(jd, longitude, timezone),
"asr": asr(jd, latitude, longitude, timezone, shadow_factor),
"maghrib": maghrib,
"isha": isha,
}
return {name: None if t is None else t + method["ihtiyat"] / 60 for name, t in times.items()}

if __name__ == "__main__":
cities = [("Jakarta", -6.2088, 106.8456, 7, "kemenag"), ("London", 51.5074, -0.1278, 1, "mwl"),
("Oslo", 59.9139, 10.7522, 2, "mwl"), ("Tromso", 69.6492, 18.9553, 2, "mwl")]
print("21 June 2026 fajr dhuhr asr maghrib isha")
for name, lat, lon, tz, key in cities:
t = prayer_times(2026, 6, 21, lat, lon, tz, METHODS[key])
print(f"{name:<8} {key:<9} {hm(t['fajr'], round_up=True)} {hm(t['dhuhr'], round_up=True)} {hm(t['asr'], round_up=True)} "
f"{hm(t['maghrib'], round_up=True)} {hm(t['isha'], round_up=True)}")

Check your work​

Run it. For 21 June 2026 you should see:

21 June 2026 fajr dhuhr asr maghrib isha
Jakarta kemenag 04:40 11:57 15:19 17:50 19:05
London mwl 02:31 13:03 17:26 21:22 23:27
Oslo mwl 02:21 13:19 18:01 22:44 00:12
Tromso mwl --:-- 12:46 17:58 --:-- --:--

London's Fajr at 02:31 and Isha at 23:27 are substitutes, and they match what libmuslim and the Muslim World League's published London table give for that day. Oslo's Isha is after midnight, and belongs to 21 June. Tromsø has no sunset on 21 June, so the code prints what exists and nothing else.

Then try the Cairo lines from the clock section, once with 3 and once with 2, and watch the whole table slide by an hour.

The whole program​

Here is the complete Python file, every piece from parts 2 to 7 in one place, 125 lines. The other six languages are assembled the same way: the file from part 3, then the Asr functions from part 5, then the method table from part 6, then prayer_times from this part.

prayer_times.py, the complete program
import math

def julian_day(year, month, day):
if month <= 2:
year -= 1
month += 12
a = year // 100
b = 2 - a + a // 4
return math.floor(365.25 * (year + 4716)) + math.floor(30.6001 * (month + 1)) + day + b - 1524.5

def sun_position(jd):
d = jd - 2451545.0 # days since J2000.0
g = math.radians((357.529 + 0.98560028 * d) % 360)
q = (280.459 + 0.98564736 * d) % 360
L = math.radians((q + 1.915 * math.sin(g) + 0.020 * math.sin(2 * g)) % 360)
e = math.radians(23.439 - 0.00000036 * d)
declination = math.degrees(math.asin(math.sin(e) * math.sin(L)))
right_ascension = math.degrees(math.atan2(math.cos(e) * math.sin(L), math.cos(L))) / 15
equation_of_time = (q / 15 - right_ascension + 12) % 24 - 12
return declination, equation_of_time * 60 # degrees, minutes

def hour_angle(latitude, declination, altitude):
"""Hours between solar noon and the moment the sun stands at `altitude` degrees."""
lat, dec, alt = (math.radians(v) for v in (latitude, declination, altitude))
cos_h = (math.sin(alt) - math.sin(lat) * math.sin(dec)) / (math.cos(lat) * math.cos(dec))
if cos_h < -1 or cos_h > 1:
return None # the sun never reaches that altitude today
return math.degrees(math.acos(cos_h)) / 15

SUNRISE_ALTITUDE = -0.833 # refraction 0.567 + half the sun's width 0.267

def solar_noon(jd, longitude, timezone):
_, eqt = sun_position(jd)
return 12 + timezone - longitude / 15 - eqt / 60 # local clock hours

def sun_event(jd, latitude, longitude, timezone, altitude, direction):
"""Local clock time when the sun reaches `altitude`, before noon (-1) or after (+1)."""
t = solar_noon(jd, longitude, timezone) # first guess, then refine at the event itself
for _ in range(2):
dec, _ = sun_position(jd + (t - timezone) / 24)
h = hour_angle(latitude, dec, altitude)
if h is None:
return None
t = solar_noon(jd + (t - timezone) / 24, longitude, timezone) + direction * h
return t

def hm(t, round_up=False):
if t is None:
return "--:--"
minutes = math.ceil(t * 60) if round_up else round(t * 60)
return f"{int(minutes // 60) % 24:02d}:{int(minutes % 60):02d}"


def asr_altitude(latitude, declination, shadow_factor):
"""Sun altitude when a stick's shadow is its noon shadow plus shadow_factor times its height."""
noon_zenith = abs(latitude - declination) # degrees between the noon sun and straight overhead
return math.degrees(math.atan(1 / (shadow_factor + math.tan(math.radians(noon_zenith)))))

def asr(jd, latitude, longitude, timezone, shadow_factor=1):
noon = solar_noon(jd, longitude, timezone)
declination, _ = sun_position(jd + (noon - timezone) / 24)
altitude = asr_altitude(latitude, declination, shadow_factor)
return sun_event(jd, latitude, longitude, timezone, altitude, +1)

METHODS = {
# key fajr isha isha interval maghrib offset ihtiyat (angles in degrees, the rest in minutes)
"mwl": dict(fajr=18.0, isha=17.0, interval=0, maghrib=0, ihtiyat=0),
"makkah": dict(fajr=18.5, isha=0.0, interval=90, maghrib=0, ihtiyat=0),
"isna": dict(fajr=15.0, isha=15.0, interval=0, maghrib=0, ihtiyat=0),
"egypt": dict(fajr=19.5, isha=17.5, interval=0, maghrib=0, ihtiyat=0),
"karachi": dict(fajr=18.0, isha=18.0, interval=0, maghrib=0, ihtiyat=0),
"turkey": dict(fajr=18.0, isha=17.0, interval=0, maghrib=0, ihtiyat=0),
"singapore": dict(fajr=20.0, isha=18.0, interval=0, maghrib=0, ihtiyat=0),
"jakim": dict(fajr=20.0, isha=18.0, interval=0, maghrib=0, ihtiyat=0),
"kemenag": dict(fajr=20.0, isha=18.0, interval=0, maghrib=0, ihtiyat=2),
"france": dict(fajr=12.0, isha=12.0, interval=0, maghrib=0, ihtiyat=0),
"russia": dict(fajr=16.0, isha=15.0, interval=0, maghrib=0, ihtiyat=0),
"dubai": dict(fajr=18.2, isha=18.2, interval=0, maghrib=0, ihtiyat=0),
"qatar": dict(fajr=18.0, isha=0.0, interval=90, maghrib=0, ihtiyat=0),
"kuwait": dict(fajr=18.0, isha=17.5, interval=0, maghrib=0, ihtiyat=0),
"jordan": dict(fajr=18.0, isha=18.0, interval=0, maghrib=0, ihtiyat=5),
"gulf": dict(fajr=19.5, isha=0.0, interval=90, maghrib=0, ihtiyat=0),
"tunisia": dict(fajr=18.0, isha=18.0, interval=0, maghrib=0, ihtiyat=0),
"algeria": dict(fajr=18.0, isha=17.0, interval=0, maghrib=0, ihtiyat=0),
"morocco": dict(fajr=19.0, isha=17.0, interval=0, maghrib=0, ihtiyat=0),
"portugal": dict(fajr=18.0, isha=0.0, interval=77, maghrib=3, ihtiyat=0),
"moonsighting": dict(fajr=18.0, isha=18.0, interval=0, maghrib=3, ihtiyat=0),
}

def prayer_times(year, month, day, latitude, longitude, timezone, method, shadow_factor=1):
"""The five prayer times as local clock hours, with the method's offsets, precaution
and the high-latitude substitute applied. None means the time does not exist."""
jd = julian_day(year, month, day)
sunrise = sun_event(jd, latitude, longitude, timezone, SUNRISE_ALTITUDE, -1)
sunset = sun_event(jd, latitude, longitude, timezone, SUNRISE_ALTITUDE, +1)
night = None if sunrise is None or sunset is None else (24 - sunset) + sunrise # hours of darkness
maghrib = None if sunset is None else sunset + method["maghrib"] / 60

fajr = sun_event(jd, latitude, longitude, timezone, -method["fajr"], -1)
if fajr is None and night is not None:
fajr = sunrise - method["fajr"] / 60 * night # angle-based substitute: the angle as a share of the night
if method["interval"]:
isha = None if maghrib is None else maghrib + method["interval"] / 60
else:
isha = sun_event(jd, latitude, longitude, timezone, -method["isha"], +1)
if isha is None and night is not None:
isha = maghrib + method["isha"] / 60 * night

times = {
"fajr": fajr,
"dhuhr": solar_noon(jd, longitude, timezone),
"asr": asr(jd, latitude, longitude, timezone, shadow_factor),
"maghrib": maghrib,
"isha": isha,
}
return {name: None if t is None else t + method["ihtiyat"] / 60 for name, t in times.items()}

if __name__ == "__main__":
cities = [("Jakarta", -6.2088, 106.8456, 7, "kemenag"), ("London", 51.5074, -0.1278, 1, "mwl"),
("Oslo", 59.9139, 10.7522, 2, "mwl"), ("Tromso", 69.6492, 18.9553, 2, "mwl")]
print("21 June 2026 fajr dhuhr asr maghrib isha")
for name, lat, lon, tz, key in cities:
t = prayer_times(2026, 6, 21, lat, lon, tz, METHODS[key])
print(f"{name:<8} {key:<9} {hm(t['fajr'], round_up=True)} {hm(t['dhuhr'], round_up=True)} {hm(t['asr'], round_up=True)} "
f"{hm(t['maghrib'], round_up=True)} {hm(t['isha'], round_up=True)}")

A year against the production library​

The last check in the series is the only one that matters for an app: not one date in one city, but every day of a year, compared against the library Muslimtify actually runs. I ran the complete Python program for all 365 days of 2026 against libmuslim's calculate_prayer_times for four cities and recorded the worst difference for each prayer.

City, methodFajrDhuhrAsrMaghribIshaTimes one side has and the other does not
Jakarta, Kemenag0 s0 s16 s0 s0 snone
London, MWL5 s0 s74 s0 s84 min on one day, else under 10 snone
Oslo, MWL8 s0 s92 s0 s84 min on one day, else under 10 snone
Tromsø, MWL0 s32 s265 cells, all inside the polar night or midnight sun

Three things in this table deserve explanation, because a comparison that only reports agreement is not a comparison.

The Asr column is the one systematic difference. libmuslim evaluates Asr from the sun's declination at the start of the day and does not refine at the event, while the code in this series refines, as it does for every other prayer. In Jakarta that is 16 seconds and never changes the printed minute. In London it changes the printed minute on about two thirds of the days of the year, always by a single minute, and the refined value is the more accurate of the two. That is a finding about libmuslim rather than about this series, and it is a one-line fix there: solve Asr the way the other four prayers are solved.

The 84 minutes in the Isha column are a single day in each city: 15 July in London and 18 August in Oslo. On those days the sun does, barely, reach 17° below the horizon, a few minutes before solar midnight. This series takes that real event. libmuslim notices that the day sits on the edge of the season and substitutes, which is what the published MWL tables do. Both are defensible readings of "the twilight has disappeared". If you are writing a timetable for a real community, follow the tables.

The Tromsø row is the polar case from earlier. libmuslim borrows a 45° day and fills every cell. This series leaves 265 of them blank. The 32 seconds on Maghrib is the one place they both compute something and differ, on the days when the sun just grazes the horizon and the two refinement strategies catch it at slightly different moments.

Everything else, Fajr, Dhuhr and Maghrib at every latitude and Isha on 363 days out of 365, agrees to within ten seconds, and all of it well inside the minute that any timetable prints.

What the series showed​

A prayer time is a sentence in a hadith about the sun. The sun is predictable, so the sentence can be computed. Two numbers come from the date alone, the sun's declination and the equation of time. Those plus your longitude give solar noon, which is Dhuhr. Noon plus an hour angle gives the moment the sun reaches any altitude: 0.833° below the horizon for sunrise and Maghrib, a twilight angle for Fajr and Isha, a shadow angle for Asr. That is the whole of the astronomy, and it fits in a hundred lines in any language.

Everything else is people. The twilight angle is a measurement made by the scholars of each country under their own sky, and the differences between countries are differences of sky, of reading, of precaution and of authority, every one of them traceable to the first generations. The far north is a fatwa about estimation. The clock is a decision by a government. An honest app computes the astronomy exactly, applies the authority's rules and nothing more, gets the clock from a source that knows the law, and says plainly when it is estimating.

That is what libmuslim tries to do and what Muslimtify shows you on your desktop. If you have read this far you now know every number in it, and where each one came from. Bring a stick.