Unexpected result in PHP sunrise function
Moderator: General Moderators
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Sorry to annoy:Kieran Huggins wrote: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;
I "pasted" your edited code into my tables.
Code: Select all
echo "<font size='-4'>".list($hour,$min) = explode(':',date_sunrise(time(), SUNFUNCS_RET_STRING, -28.0361, 148.5814, 90, 10));
$sunrise = ($hour % 24).':'.$min;
echo $sunrise."</font>";Could you please point out where I went wrong?
Cheers
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
Code: Select all
list($hour,$min) = explode(':',date_sunrise(time(), SUNFUNCS_RET_STRING, -28.0361, 148.5814, 90, 10));
$sunrise = ($hour % 24).':'.$min;
echo "<font size='-4'>".$sunrise."</font>";I'd rather cure the disease and not hide the symptoms.
see http://bugs.php.net/bug.php?id=32820
They have added two loops that take care of the problem(ext/php_date.c)
I don't see how php >= 5.1.2 can return 29 hours from date_sunrise()
see http://bugs.php.net/bug.php?id=32820
They have added two loops that take care of the problem
Code: Select all
N = (calc_sunset ? h_set : h_rise) + gmt_offset;
while (N > 24) {
N -= 24;
}
while (N < 0) {
N += 24;
}I don't see how php >= 5.1.2 can return 29 hours from date_sunrise()
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
I did try. I worked this out with help from the net.Everah wrote:Have you tried messing with the GMT offset to see what happens?
Code: Select all
<?php
$original_tz = getenv('TZ');
$format = "d/m/Y H:i";
// Server time:
$server_time = time();
echo 'Server time: ' . date($format, time()) . '';
// GMT time:
$gm_time = $server_time - date('Z', $server_time);
echo "GMT time: " . date($format, $gm_time) . "";
$a_time = $gm_time + date('Z', time());
//Roma
putenv('TZ=' . $original_tz);
putenv('TZ=Australia/Brisbane');
echo '<p>Australia/Brisbane: ' . date($format, $a_time) . "";
?>- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
Oops! I have 5.1.1 installed herevolka wrote:I'd rather cure the disease and not hide the symptoms.
see http://bugs.php.net/bug.php?id=32820
They have added two loops that take care of the problem(ext/php_date.c)Code: Select all
N = (calc_sunset ? h_set : h_rise) + gmt_offset; while (N > 24) { N -= 24; } while (N < 0) { N += 24; }
I don't see how php >= 5.1.2 can return 29 hours from date_sunrise()
Here's my output:
Code: Select all
echo date_sunrise(time(), SUNFUNCS_RET_STRING, -28.0361, 148.5814, 90, 10);
echo '<br/>version: '.phpversion();Code: Select all
29:17
version: 5.1.1Just to clarify - the PHP version was 5.0.4volka wrote:hm, what php version do you actually use?
Your webserver claimsBut php4 does not support date_sunrise. Did you install e.g. a pecl extension?Server: Apache/2.0.47 (Fedora)
X-Powered-By: PHP/4.3.8
http://www.php.net/ChangeLog-5.phpVersion 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)
At least that's what phpinfo tells me
- neel_basu
- Forum Contributor
- Posts: 454
- Joined: Wed Dec 06, 2006 9:33 am
- Location: Picnic Garden, Kolkata, India
Please Tell Which Zenith is perfect for youneel_basu wrote:IT WOULD BE THE BEST SOLUTION
========================
If the Above Try doesn't Work Choose The perfect zenith For You
By The following CodesSelect The Zenith Thats Perfect For You And Use ItCode: 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"; } ?>
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
My previous code will work regardless of PHP version, although it does add a little cruft.