cloudy

Author Topic: Sunrise - Sunset PHP Script  (Read 11860 times)

0 Members and 1 Guest are viewing this topic.

Offline TNETWeather

  • Kevin Reed (KrelvinAZ)
  • Global Moderator
  • Posts: 5,859
  • Gremlins are at work...
  • Mesa, AZ
    • TNET Weather Station - Mesa AZ
Re: PHP code for day/night, sunrise/sunset times
« Reply #30 on: May 23, 2008, 01:11:25 AM »
Can't respond to the date you saw as that is kind of relative to when you did it.  It looked okay when I looked at it.

However, I have identified the problem with the function date_sunset.

On my server it is returning:   -4:-3

On the other server that is working, it is returning:  19:27

the PHP on my server is older so it is most likely a bug that was fixed.

All you need is Time, Aptitude and Desire ... and you can build just about anything...

Offline MCHALLIS

  • Posts: 2,102
  • Long Beach, WA USA
    • Weather for Long Beach, WA USA
Re: PHP code for day/night, sunrise/sunset times
« Reply #31 on: May 23, 2008, 01:13:42 AM »
I wish I could find "moon_rise / moon_set time" PHP code, google turns up nothing.  :(

Offline TNETWeather

  • Kevin Reed (KrelvinAZ)
  • Global Moderator
  • Posts: 5,859
  • Gremlins are at work...
  • Mesa, AZ
    • TNET Weather Station - Mesa AZ
Re: PHP code for day/night, sunrise/sunset times
« Reply #32 on: May 23, 2008, 01:14:52 AM »

Found a couple references to exactly what I am seeing... 

Reproduce code:
---------------
<?php
echo date("D M d Y"). ', sunset time : ' .date_sunset(time(),
SUNFUNCS_RET_STRING, 40, -83, 90, -4);
?>

Expected result:
----------------
I would expect to see:

Sun Apr 24 2005, sunset time : 20:14

Actual result:
--------------
I actually see:

Sun Apr 24 2005, sunset time : -3:-4



All you need is Time, Aptitude and Desire ... and you can build just about anything...

Offline TNETWeather

  • Kevin Reed (KrelvinAZ)
  • Global Moderator
  • Posts: 5,859
  • Gremlins are at work...
  • Mesa, AZ
    • TNET Weather Station - Mesa AZ
Re: PHP code for day/night, sunrise/sunset times
« Reply #33 on: May 23, 2008, 01:15:23 AM »
I wish I could find "moon_rise / moon_set time" PHP code, google turns up nothing.  :(

That is what I was looking for.  I've got the "math" to do it, but I'm not good and converting that to PHP.

All you need is Time, Aptitude and Desire ... and you can build just about anything...

Offline MCHALLIS

  • Posts: 2,102
  • Long Beach, WA USA
    • Weather for Long Beach, WA USA
Re: PHP code for day/night, sunrise/sunset times
« Reply #34 on: May 23, 2008, 01:19:44 AM »
Found a couple references to exactly what I am seeing... 

Reproduce code:
---------------
<?php
echo date("D M d Y"). ', sunset time : ' .date_sunset(time(),
SUNFUNCS_RET_STRING, 40, -83, 90, -4);
?>

Expected result:
----------------
I would expect to see:

Sun Apr 24 2005, sunset time : 20:14

Actual result:
--------------
I actually see:

Sun Apr 24 2005, sunset time : -3:-4




http://bugs.php.net/bug.php?id=32820
that was fixed in PHP 5.1.2

I am running Version 5.2.5 and just realized it is time to upgrade to Version 5.2.6, wish me luck  :wink:

Offline MCHALLIS

  • Posts: 2,102
  • Long Beach, WA USA
    • Weather for Long Beach, WA USA
Re: PHP code for day/night, sunrise/sunset times
« Reply #35 on: May 23, 2008, 01:37:22 AM »
another update in code in 1st post

Ver. 1.04 05/22/08 added php version to debugging info
Requires PHP 5 (version 5.1.3 or higher recommended, due to date_sunset bug fixes in 5.1.3)

Sample output in verbose mode:

Good day
Sunset will occur at 08:53 PM PDT

Settings and Variables:

Current PHP version: 5.2.5
May 22 2008 07:31:15 PM PDT (server time)
May 23 2008 02:31:15 AM GMT (GMT time)

myTZ = America/Los_Angeles
tzoffset = -7
lat = 46.36
long = -124.02
Zenith = 90.833333333333

Sunrise will occur at 05:31 AM PDT
Sunset will occur at 08:53 PM PDT

« Last Edit: May 23, 2008, 01:47:50 AM by MCHALLIS »