Sunrise equation

The sunrise equation can be used to derive the time of sunrise and sunset for any solar declination and latitude in terms of local solar time when sunrise and sunset actually occur. It is:
where:
Theory of the equation.
The Earth rotates at an angular velocity of 15°/hour. Therefore, the expression formula_5 gives the interval of time (in hours) before and after local solar noon that sunrise or sunset will occur.
The sign convention is typically that the observer latitude formula_3 is 0 at the equator, positive for the Northern Hemisphere and negative for the Southern Hemisphere, and the solar declination formula_4 is 0 at the vernal and autumnal equinoxes when the sun is exactly above the equator, positive during the Northern Hemisphere summer and negative during the Northern Hemisphere winter.
The expression above is always applicable for latitudes between the Arctic Circle and Antarctic Circle. North of the Arctic Circle or south of the Antarctic Circle, there is at least one day of the year with no sunrise or sunset. Formally, there is a sunrise or sunset when formula_8 during the Northern Hemisphere summer, and when formula_9 during the Northern Hemisphere winter. For locations outside these latitudes, it is either 24-hour daytime or 24-hour nighttime.
Generalized equation.
The equation above neglects the influence of atmospheric refraction (which lifts the solar disc — i.e. makes the solar disc appear higher in the sky — by approximately 0.6° when it is on the horizon) and the non-zero angle subtended by the solar disc — i.e. the apparent diameter of the sun — (about 0.5°). The times of the rising and the setting of the upper solar limb as given in astronomical almanacs correct for this by using the more general equation
with the altitude (a) of the center of the solar disc set to about −0.83° (or −50 arcminutes).
Complete calculation on Earth.
The generalized equation relies on a number of other variables which need to be calculated before it can itself be calculated. These equations have the solar-earth constants substituted with angular constants expressed in degrees.
Calculate current Julian day.
where:
Mean solar time.
where:
Solar mean anomaly.
where:
Equation of the center.
where:
Ecliptic longitude.
where:
Solar transit.
where:
Declination of the Sun.
where:
Hour angle.
"This is the equation from above with corrections for atmospherical refraction and solar disc diameter."
where:
For observations on a sea horizon needing an elevation-of-observer correction, add formula_27, or formula_28 to the −0.83° in the numerator's sine term. This corrects for both apparent dip and terrestrial refraction. For example, for an observer at 10,000 feet, add (−115°/60) or about −1.92° to −0.83°.
Calculate sunrise and sunset.
where: