There are different algorithms available to compute the position of the sun from which sunrise and sunset can be derived. They have different accuracy. Does anyone know which is used for the PHP functions date_sunrise
, date_sunset
and date_sun_info
?
-
3PHP is open source: php.net/downloads.php grab it and examine the code for those functions.– Marc BOct 24, 2013 at 18:44
-
1or look at the source at github.com/php line 4602– bitWorkingOct 24, 2013 at 18:56
2 Answers
The date_sunrise
and date_sunset
functions call the C function php_do_date_sunrise_sunset
in date.c, which uses the timelib
library.
The timelib
function timelib_astro_rise_set_altitude
is well commented (see source), and uses the generalised sunrise equation to calculate the diurnal arc.
The date_sun_info
function also calls the same timelib
function.
-
3I notice you've not accepted any answers to your questions — have you seen How does accepting an answer work? Nov 7, 2013 at 11:04
PHP uses public domain algorithms by Paul Schlyter, some more info on his website: http://www.stjarnhimlen.se/comp/riset.html
Other, more accurate, algorithms for sunrise and sunset time calculations are the ones described in Astronomical Algorithms by Jean Meeus. The NOAA Sun calculator as well as Sunrise-sunset site are using those improved calculations.
You can find a PHP implementation of such algorithms at this github project