Arty Ziff Posted January 29, 2017 Share Posted January 29, 2017 (edited) I've been working a lot with time calculations, and have a few that require sunrise / sunset. All of the online sources such as the Navy Observatory and just Googling consistently produce the same numbers. However, using the PHP sunrise sunset functions, I can never reproduce what I'm seeing from other sources. One of the variables is the Zenith. 90 is often used as a "ball-park", but usually it's more accurate around 90.833. In any case, even adjusting the Zenith, I'm unable to get anything closer than a few minutes to online sources consistently. My neck of the woods is Seattle / Tacoma, specifically the Lakewood area around McChord Air Force Base. Here's a sample of the code from a class I wrote to test the PHP function... public function sunrise() { $sunriseL = date_sunrise(time(),SUNFUNCS_RET_STRING,47.2529,-122.4443,90.833,-($z_offset)); $sunrise[0] = $sunriseL; $sunrise_array = explode(":",$sunriseL); $sunriseZ_hr = $sunrise_array[0] + $z_offset; // Add Z offset to local time... if ($sunriseZ_hr >= 24) { $sunriseZ_hr = $sunriseZ_hr - 24; } if (strlen($sunriseZ_hr) == 1) {$sunriseZ_hr = str_pad($sunriseZ_hr,2,"0",STR_PAD_LEFT); } $sunrise[1] = $sunriseZ_hr . ":" . $sunrise_array[1]; return $sunrise; // Return local and Z in an array... } Any ideas why PHP sunrise / sunset don't reproduce what other sources say? In the end, the sunrise / sunset algorithm is available and not all that complex, I can write my own function and get better accuracy. But that really astonishes me that the PHP functions are inconsistent with *everyone* else. Edited January 29, 2017 by Arty Ziff Quote Link to comment Share on other sites More sharing options...
ignace Posted January 29, 2017 Share Posted January 29, 2017 $z_offset is undefined. Please turn on error_reporting like so: error_reporting(-1); ini_set('display_errors', 1); Also what is your date.timezone setting? echo date_default_timezone_get(); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.