Time Above Horizon, or Daylight Calculator
Note: This derivation ignores the fact that the sun moves along the ecliptic by 360 degrees in 365.25 days. It also ignores the effects of atmospheric refraction, which enable us to see the sun even when it is below the geometrical horizon.

Figure 1

Figure 2
In Figure 1 the declination circle for the sun is cut by the horizon circle. The angle A corresponds to the path of the sun below the horizon, hence it is invisible then.
In Figure 2, a side view, the horizon line makes an angle L, the observer's latitude, with respect to the north celestial pole,ncp. The sun's celestial latitude is G.
In Figure 3, assuming uniform daily motion on the declination circle, we determine the fraction of the day spent in darkness in terms of the angle A, which can be obtained graphically by measuring x and a in Fig.2. With the aid of Fig 2. we can also determine that
(a-x)/a = tanL*tanG., derivation

So the fraction of the day spent in darkness is
dark/day=arc_cos(tanL*tanG)/180.


Figure 3