1

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?

2

2 Answers 2

9
+50

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.

1
2

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.