Prayer times, part 5: Asr and the shadow
Every prayer so far has been about the horizon: the sun crossing it, or sitting some number of degrees below it. Asr is different. Asr is about a shadow.
That makes it the one prayer time you can measure with no instrument but a stick, and it is also the one prayer whose time is set by your madhhab rather than by your country. Both of those facts come straight out of the texts in part 1, and both end up as a single line in the code.
Part 1 covered the sources. Part 2 found the sun. Part 3 computed sunrise, Dhuhr and Maghrib. Part 4 computed Fajr and Isha. This part completes the five. The full series is under the prayer time calculation tag.
What the texts say
The hadith of Abdullah ibn Amr in part 1 gives the end of Dhuhr and the start of Asr in one phrase: Dhuhr lasts from the sun's decline "for as long as a man's shadow is the length of his height, until Asr has come". Asr begins when your shadow is as long as you are tall.
The hadith of Jibril adds the detail that split the schools. On the first day Jibril prayed Asr "when the shadow of a thing was equal to it", and on the second day "when the shadow of a thing was twice it". Malik, ash-Shafi'i and Ahmad read the first day as the start of Asr and the second as its preferred end. Abu Hanifa read the second day as the start. So for three schools Asr begins at one shadow length, and for the Hanafi school at two.
There is one more detail the jurists added, and it matters for the math. At noon a stick already has a shadow, short or long depending on the season and where you live. The schools agree that this noon shadow, fay' az-zawal, does not count. Asr begins when the shadow has grown by one stick height beyond whatever it was at noon, or by two for the Hanafi school.
From a shadow to an angle
A stick's shadow is simple geometry. If the sun is at altitude a above the horizon, a stick of height 1 casts a shadow of length 1 / tan(a). High sun, short shadow. Low sun, long shadow.
At noon the sun is as high as it gets, and from part 2 we know how high: it is overhead minus the gap between your latitude and today's declination. In Jakarta on 17 October 2026 that gap is 3.0°, so the noon sun is 87.0° up and the noon shadow is tan(3.0°), about 0.05 stick heights. In Istanbul the same day the gap is 50.2° and the noon shadow is 1.2 stick heights, already longer than the stick.
Asr begins when the shadow equals the noon shadow plus one stick height (or two). Put that into the shadow formula and solve for the altitude:
noon_shadow = tan( |latitude - declination| )
shadow at Asr = noon_shadow + n n = 1 for most schools, 2 for Hanafi
altitude at Asr = atan( 1 / (noon_shadow + n) )
For Jakarta on 17 October: atan(1 / (0.05 + 1)) is 43.5°, and atan(1 / (0.05 + 2)) is 26.0°. Asr begins when the afternoon sun has come down to 43.5° above the horizon, or 26.0° for the Hanafi school.
And now we are back on familiar ground. "At what time does the sun reach 43.5° above the horizon, after noon?" is exactly the question sun_event from part 3 answers. The only difference from every earlier use is that the altitude is positive. The function does not care.
Why Asr is a madhhab setting, not a country setting
Look at what goes into the Asr altitude: your latitude, today's declination, and the number n. There is no twilight, no observation of the sky, nothing for a national authority to measure and decide. The only choice is n, and n is a question of which reading of the hadith of Jibril you follow. That is a question of madhhab.
So Muslimtify keeps Asr separate from the calculation method. You pick Kemenag or Diyanet or ISNA for Fajr and Isha, and you pick your madhhab for Asr, and the two settings do not touch. A Hanafi in Jakarta uses Kemenag's 20° and the two-shadow Asr. A Shafi'i in Istanbul uses Diyanet's angles and the one-shadow Asr. The calculation methods page in the docs describes the setting.
The code
Add this to the file from part 3, in place of its last block. asr_altitude is the formula above. asr computes the noon declination, turns it into the altitude, and hands the altitude to sun_event to find the time.
- Python
- TypeScript
- Go
- Rust
- Kotlin
- Dart
- C
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)
if __name__ == "__main__":
jd = julian_day(2026, 10, 17)
lat, lon, tz = -6.2088, 106.8456, 7 # Jakarta, WIB
standard = asr(jd, lat, lon, tz, 1)
hanafi = asr(jd, lat, lon, tz, 2)
print(f"asr, shadow = height {hm(standard)} (Shafi'i, Maliki, Hanbali)")
print(f"asr, shadow = 2 x height {hm(hanafi)} (Hanafi)")
ihtiyat = 2 / 60
print(f"kemenag {hm(standard + ihtiyat, round_up=True)} (standard, +2 min, rounded up)")
/** Sun altitude when a stick's shadow is its noon shadow plus `shadowFactor` times its height. */
function asrAltitude(latitude: number, declination: number, shadowFactor: number): number {
const noonZenith = Math.abs(latitude - declination); // degrees between the noon sun and straight overhead
return deg(Math.atan(1 / (shadowFactor + Math.tan(rad(noonZenith)))));
}
function asr(jd: number, latitude: number, longitude: number, timezone: number, shadowFactor = 1): number | null {
const noon = solarNoon(jd, longitude, timezone);
const { declination } = sunPosition(jd + (noon - timezone) / 24);
return sunEvent(jd, latitude, longitude, timezone, asrAltitude(latitude, declination, shadowFactor), 1);
}
const jd = julianDay(2026, 10, 17);
const [lat, lon, tz] = [-6.2088, 106.8456, 7]; // Jakarta, WIB
const standard = asr(jd, lat, lon, tz, 1);
const hanafi = asr(jd, lat, lon, tz, 2);
console.log(`asr, shadow = height ${hm(standard)} (Shafi'i, Maliki, Hanbali)`);
console.log(`asr, shadow = 2 x height ${hm(hanafi)} (Hanafi)`);
const ihtiyat = 2 / 60;
console.log(`kemenag ${hm(standard === null ? null : standard + ihtiyat, true)} (standard, +2 min, rounded up)`);
// asrAltitude is the sun's altitude when a stick's shadow is its noon shadow
// plus shadowFactor times its height.
func asrAltitude(latitude, declination, shadowFactor float64) float64 {
noonZenith := math.Abs(latitude - declination) // degrees between the noon sun and straight overhead
return deg(math.Atan(1 / (shadowFactor + math.Tan(rad(noonZenith)))))
}
func asr(jd, latitude, longitude, timezone, shadowFactor float64) (float64, bool) {
noon := solarNoon(jd, longitude, timezone)
declination, _ := sunPosition(jd + (noon-timezone)/24)
return sunEvent(jd, latitude, longitude, timezone, asrAltitude(latitude, declination, shadowFactor), 1)
}
func main() {
jd := julianDay(2026, 10, 17)
lat, lon, tz := -6.2088, 106.8456, 7.0 // Jakarta, WIB
standard, sOk := asr(jd, lat, lon, tz, 1)
hanafi, hOk := asr(jd, lat, lon, tz, 2)
fmt.Printf("asr, shadow = height %s (Shafi'i, Maliki, Hanbali)\n", hm(standard, sOk, false))
fmt.Printf("asr, shadow = 2 x height %s (Hanafi)\n", hm(hanafi, hOk, false))
ihtiyat := 2.0 / 60
fmt.Printf("kemenag %s (standard, +2 min, rounded up)\n", hm(standard+ihtiyat, sOk, true))
}
/// Sun altitude when a stick's shadow is its noon shadow plus `shadow_factor` times its height.
fn asr_altitude(latitude: f64, declination: f64, shadow_factor: f64) -> f64 {
let noon_zenith = (latitude - declination).abs(); // degrees between the noon sun and straight overhead
(1.0 / (shadow_factor + noon_zenith.to_radians().tan())).atan().to_degrees()
}
fn asr(jd: f64, latitude: f64, longitude: f64, timezone: f64, shadow_factor: f64) -> Option<f64> {
let noon = solar_noon(jd, longitude, timezone);
let (declination, _) = sun_position(jd + (noon - timezone) / 24.0);
sun_event(jd, latitude, longitude, timezone, asr_altitude(latitude, declination, shadow_factor), 1.0)
}
fn main() {
let jd = julian_day(2026, 10, 17);
let (lat, lon, tz) = (-6.2088, 106.8456, 7.0); // Jakarta, WIB
let standard = asr(jd, lat, lon, tz, 1.0);
let hanafi = asr(jd, lat, lon, tz, 2.0);
println!("asr, shadow = height {} (Shafi'i, Maliki, Hanbali)", hm(standard, false));
println!("asr, shadow = 2 x height {} (Hanafi)", hm(hanafi, false));
let ihtiyat = 2.0 / 60.0;
println!("kemenag {} (standard, +2 min, rounded up)", hm(standard.map(|t| t + ihtiyat), true));
}
/** Sun altitude when a stick's shadow is its noon shadow plus [shadowFactor] times its height. */
fun asrAltitude(latitude: Double, declination: Double, shadowFactor: Double): Double {
val noonZenith = abs(latitude - declination) // degrees between the noon sun and straight overhead
return deg(atan(1 / (shadowFactor + tan(rad(noonZenith)))))
}
fun asr(jd: Double, latitude: Double, longitude: Double, timezone: Double, shadowFactor: Double = 1.0): Double? {
val noon = solarNoon(jd, longitude, timezone)
val sun = sunPosition(jd + (noon - timezone) / 24)
return sunEvent(jd, latitude, longitude, timezone, asrAltitude(latitude, sun.declination, shadowFactor), 1)
}
fun main() {
val jd = julianDay(2026, 10, 17)
val lat = -6.2088
val lon = 106.8456
val tz = 7.0 // Jakarta, WIB
val standard = asr(jd, lat, lon, tz, 1.0)
val hanafi = asr(jd, lat, lon, tz, 2.0)
println("asr, shadow = height ${hm(standard)} (Shafi'i, Maliki, Hanbali)")
println("asr, shadow = 2 x height ${hm(hanafi)} (Hanafi)")
val ihtiyat = 2.0 / 60
println("kemenag ${hm(standard?.plus(ihtiyat), true)} (standard, +2 min, rounded up)")
}
/// Sun altitude when a stick's shadow is its noon shadow plus [shadowFactor] times its height.
double asrAltitude(double latitude, double declination, double shadowFactor) {
final noonZenith = (latitude - declination).abs(); // degrees between the noon sun and straight overhead
return deg(atan(1 / (shadowFactor + tan(rad(noonZenith)))));
}
double? asr(double jd, double latitude, double longitude, double timezone, {double shadowFactor = 1}) {
final noon = solarNoon(jd, longitude, timezone);
final sun = sunPosition(jd + (noon - timezone) / 24);
return sunEvent(jd, latitude, longitude, timezone, asrAltitude(latitude, sun.declination, shadowFactor), 1);
}
void main() {
final jd = julianDay(2026, 10, 17);
const lat = -6.2088, lon = 106.8456, tz = 7.0; // Jakarta, WIB
final standard = asr(jd, lat, lon, tz, shadowFactor: 1);
final hanafi = asr(jd, lat, lon, tz, shadowFactor: 2);
print("asr, shadow = height ${hm(standard)} (Shafi'i, Maliki, Hanbali)");
print('asr, shadow = 2 x height ${hm(hanafi)} (Hanafi)');
const ihtiyat = 2.0 / 60;
print('kemenag ${hm(standard == null ? null : standard + ihtiyat, roundUp: true)} (standard, +2 min, rounded up)');
}
/* Sun altitude when a stick's shadow is its noon shadow plus shadow_factor times its height. */
static double asr_altitude(double latitude, double declination, double shadow_factor) {
double noon_zenith = fabs(latitude - declination); /* degrees between the noon sun and straight overhead */
return deg(atan(1 / (shadow_factor + tan(rad(noon_zenith)))));
}
static double asr(double jd, double latitude, double longitude, double timezone, double shadow_factor) {
double noon = solar_noon(jd, longitude, timezone);
sun_position_t sun = sun_position(jd + (noon - timezone) / 24);
return sun_event(jd, latitude, longitude, timezone, asr_altitude(latitude, sun.declination, shadow_factor), 1);
}
int main(void) {
double jd = julian_day(2026, 10, 17);
double lat = -6.2088, lon = 106.8456, tz = 7; /* Jakarta, WIB */
double standard = asr(jd, lat, lon, tz, 1);
double hanafi = asr(jd, lat, lon, tz, 2);
char a[8];
hm(standard, false, a);
printf("asr, shadow = height %s (Shafi'i, Maliki, Hanbali)\n", a);
hm(hanafi, false, a);
printf("asr, shadow = 2 x height %s (Hanafi)\n", a);
double ihtiyat = 2.0 / 60;
hm(standard + ihtiyat, true, a);
printf("kemenag %s (standard, +2 min, rounded up)\n", a);
return 0;
}
One subtlety. asr_altitude uses the declination at noon, and sun_event then refines the time using the declination at Asr itself. Between noon and Asr the declination moves by a few hundredths of a degree, which changes the shadow by less than a thousandth of a stick height. libmuslim takes the slightly simpler route of using the start-of-day declination for the whole Asr calculation. The two agree to within four seconds for Jakarta, which is why the post does not bother to recompute the altitude inside the loop.
Check your work
Run it. For Jakarta on 17 October 2026 you should see:
asr, shadow = height 14:45 (Shafi'i, Maliki, Hanbali)
asr, shadow = 2 x height 15:56 (Hanafi)
kemenag 14:48 (standard, +2 min, rounded up)
The last line is the Kemenag timetable's Asr for Jakarta and what Muslimtify shows by default. Switch the madhhab setting to Hanafi and it will show 15:59, the second line plus the same two minutes and rounding.
The gap between the two schools is 71 minutes in Jakarta today. It is not the same everywhere: the shadow grows faster when the sun is lower in the sky, so in winter at higher latitudes the two Asrs can be less than half an hour apart, and in Jakarta, where the afternoon sun stays high for a long time, they are further apart than almost anywhere.
Then the stick test, which for Asr is the real thing and not a metaphor. Find a straight stick, a pole, or a doorframe on flat ground in the sun. At 11:38 measure its shadow and mark the length. Then add the stick's own height to that mark. When the shadow reaches the new mark, look at your watch. If the sky is clear, it will say 14:45, give or take the care you took with the measuring. You have just computed Asr the way the Companions did.
What to carry into the rest of the series
With Asr the five prayers are complete. Every one of them reduced to the same shape: a date gives the sun's declination and the equation of time, those plus your longitude give solar noon, and noon plus an hour angle gives the time the sun reaches some altitude. The altitude is −0.833° for sunrise and sunset, a twilight angle for Fajr and Isha, and a shadow angle for Asr. The whole timetable is one formula asked five ways.
What remains is the part that is not astronomy. Part 6 goes through the national standards one by one, Kemenag, Diyanet, Umm al-Qura and the rest, and shows what each one adds on top of the formula: precaution minutes, rounding rules, Ramadan exceptions, and the regional corrections that Muslimtify intentionally leaves out. Part 7, the last, deals with the places where the formula gives no answer at all, in the far north, and with the clock, which is not astronomy either. Then it puts everything into a single program and checks it against libmuslim for a whole year.
