About the Time of Sunrise and Sunset
The times of sunrise and sunset are calculated as the times of morning and evening that
the sun is apparently at the horizon. The sun would normally appear to be exactly on the
horizon when its altitude angle is zero degrees, except that
the atmosphere refracts sunlight when it's low in the sky, and the observer's elevation
above sea level also impacts the apparent time of sunrise and sunset. The difference
between the time of apparent sunrise or sunset and the time when the sun's altitude angle
is zero is usually on the order of several minutes, so it's necessary to correct for these
factors in order to obtain an accurate result.
The times of sunrise and sunset are calculated by computing the hour angle when the
altitude angle is a certain value, then converting the hour angle
to clock time. The value used for the altitude angle when the sun is apparently on the
horizon is:
Al = -0.8333 - 0.347 * sqrt (elevation in meters)
If we then take the altitude angle equation:
sin (Al) = [cos (L) * cos (D) * cos (H)] + [sin (L) * sin (D)]
where:
Al = Solar altitude angle
L = Latitude (negative for Southern Hemisphere)
D = Declination (negative for Southern Hemisphere)
H = Hour angle
and solve for the hour angle, setting Al equal to the equation above that corrects for
refraction and elevation, we get:
H = cos-1[-1 * (sin (L) * sin (D) - sin (-0.8333 - 0.0347 (sqrt (elev)))) / (cos (L) * cos
(D))]
Note that "cos-1" represents the inverse cosine function. The hour angle is
converted to a number of minutes by multiplying the angle by 4 minutes per degree of hour
angle, then that number of minutes is subtracted from 12:00 noon for the time of sunrise
and added to 12:00 noon for the time of sunset.