Jump to content

Sunrise / Sunset function not accurate...


Arty Ziff

Recommended Posts

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 by Arty Ziff
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.