Unexpected result in PHP sunrise function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

woger
Forum Newbie
Posts: 13
Joined: Tue Jan 02, 2007 4:03 am

Unexpected result in PHP sunrise function

Post by woger »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I'm using the sunrise function pretty much as per the manual.

Code: Select all

echo "<font size='-4'>".date_sunrise(time(), SUNFUNCS_RET_STRING, -28.0361, 148.5814, 90, 10) ."</font>";
But, the time it returns is 29.13, where actual sunrise is 5.13.

My server is on PST time (GMT -8) and I want sunrise for GMT +10.

It can be viewed at http://www.maranoa.org.au/xoops/index.php.

My questions are:
how do I fix it?
Some people say they see it OK - as in 5.13. Why is that?
Look forward to your reply.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

That's very strange. Particularly with regard to
http://www.maranoa.org.au/xoops/index.php wrote:St George 29:17 19:01
not beeing a valid date at all.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

It's 24 hours different to what you're expecting. Sounds like a date problem somewhere.
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

Make A Slight Changes On latitude and longitude
And Test It
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

IT WOULD BE THE BEST SOLUTION
========================
If the Above Try doesn't Work Choose The perfect zenith For You
By The following Codes

Code: Select all

<?php
$lat = 22.32;
$lng = 88.24;
for($i=250;$i>=80;$i--)
  {
    echo "With zenith : ".$i."-->".date_sunrise(time(), SUNFUNCS_RET_STRING, $lat, $lng, $i, 5.5)."<br />\n";
  }
?>
Select The Zenith Thats Perfect For You And Use It
woger
Forum Newbie
Posts: 13
Joined: Tue Jan 02, 2007 4:03 am

Post by woger »

volka wrote:That's very strange. Particularly with regard to
http://www.maranoa.org.au/xoops/index.php wrote:St George 29:17 19:01
not beeing a valid date at all.
Volka, they are sunrise and sunset times - not dates.
The date is worked out in the actual PHP function - which is where I guess the problem is. Not in the PHP function, but in server time vs local time :)

As for Zenith, dropped the code in - and you can see the result!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

woger wrote:Volka, they are sunrise and sunset times - not dates.
And what is 29 hours? am or pm?
Even a Bajoran day has only 26 hours ;)
woger
Forum Newbie
Posts: 13
Joined: Tue Jan 02, 2007 4:03 am

Post by woger »

Therein lies my problem. I was expecting 5.13.

For some reason, (becuase of timezones I expect), it's adding 24 hours to arrive at 5.13 + 24 = 29.13.

I could have tried deleting 24 from the time, but I'd like to work out why the error is occuring.

Cheers
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

Sounds like a bug.

I would use the modulo operator to fix it:

Code: Select all

$sunrise_time = date_sunrise(time(), SUNFUNCS_RET_STRING, -28.0361, 148.5814, 90, 10) % 24;
woger
Forum Newbie
Posts: 13
Joined: Tue Jan 02, 2007 4:03 am

Post by woger »

Kieran Huggins wrote:Sounds like a bug.

I would use the modulo operator to fix it:

Code: Select all

$sunrise_time = date_sunrise(time(), SUNFUNCS_RET_STRING, -28.0361, 148.5814, 90, 10) % 24;
I had seen info about a bug when the time difference was a certian amount, but I'm a newb!!!

Used the modulo thingy - it now returns 5, rather than 5.17.
Can I fix that?

Cheers
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

brain fart.... please hold.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

hm, what php version do you actually use?
Your webserver claims
Server: Apache/2.0.47 (Fedora)
X-Powered-By: PHP/4.3.8
But php4 does not support date_sunrise. Did you install e.g. a pecl extension?

http://www.php.net/ChangeLog-5.php
Version 5.1.2
12-Jan-2006
...
Fixed bug #32820 (date_sunrise and date_sunset don't handle GMT offset well). (Derick)
...
Fixed bug #30937 (date_sunrise() & date_sunset() don't handle endless day/night at high latitudes). (Derick)
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

I'm getting the same behaviour with PHP 5.1.2

This code will work, though it's less awesome than I hoped :-(

Code: Select all

list($hour,$min) = explode(':',date_sunrise(time(), SUNFUNCS_RET_STRING, -28.0361, 148.5814, 90, 10));
$sunrise = bcmod($hour,'24').':'.$min;
woger
Forum Newbie
Posts: 13
Joined: Tue Jan 02, 2007 4:03 am

Post by woger »

Kieran Huggins wrote:I'm getting the same behaviour with PHP 5.1.2

This code will work, though it's less awesome than I hoped :-(

Code: Select all

list($hour,$min) = explode(':',date_sunrise(time(), SUNFUNCS_RET_STRING, -28.0361, 148.5814, 90, 10));
$sunrise = bcmod($hour,'24').':'.$min;
I get an error:
Fatal error: Call to undefined function bcmod() in
Perhaps it's the version of PHP - 5.0.x I think
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

you don't need bcmod after all, I just left it from earlier experimenting:

Code: Select all

list($hour,$min) = explode(':',date_sunrise(time(), SUNFUNCS_RET_STRING, -28.0361, 148.5814, 90, 10));
$sunrise = ($hour % 24).':'.$min;
Post Reply