Page 2 of 2

Posted: Tue Jan 02, 2007 5:10 pm
by RobertGonzalez
Have you tried messing with the GMT offset to see what happens?

Posted: Tue Jan 02, 2007 5:15 pm
by woger
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;
Sorry to annoy:

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>";
But obviously, I haven't quite got the hang of everything you've done.
Could you please point out where I went wrong?

Cheers

Posted: Tue Jan 02, 2007 5:19 pm
by Kieran Huggins

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>";

Posted: Tue Jan 02, 2007 5:28 pm
by volka
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

Code: Select all

N = (calc_sunset ? h_set : h_rise) + gmt_offset;
while (N > 24) {
	N -= 24;
}
while (N < 0) {
	N += 24;
}
(ext/php_date.c)
I don't see how php >= 5.1.2 can return 29 hours from date_sunrise()

Posted: Tue Jan 02, 2007 5:30 pm
by RobertGonzalez
Well done volka. My hats off to you. That was a good find.

Posted: Tue Jan 02, 2007 5:38 pm
by woger
Everah wrote:Have you tried messing with the GMT offset to see what happens?
I did try. I worked this out with help from the net.

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) . "";


?>
But then I couldn't work that back into the sunrise "function"??

Posted: Tue Jan 02, 2007 5:50 pm
by woger
Thanks guys

I have ben trying to solve this for months.

Thanks for your persistence and patience

Cheers

Posted: Tue Jan 02, 2007 7:14 pm
by Kieran Huggins
volka 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

Code: Select all

N = (calc_sunset ? h_set : h_rise) + gmt_offset;
while (N > 24) {
	N -= 24;
}
while (N < 0) {
	N += 24;
}
(ext/php_date.c)
I don't see how php >= 5.1.2 can return 29 hours from date_sunrise()
Oops! I have 5.1.1 installed here :-)

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.1

Posted: Tue Jan 02, 2007 11:22 pm
by woger
volka wrote: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)
Just to clarify - the PHP version was 5.0.4
At least that's what phpinfo tells me

Posted: Tue Jan 02, 2007 11:26 pm
by neel_basu
neel_basu wrote: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
Please Tell Which Zenith is perfect for you

Posted: Wed Jan 03, 2007 10:09 am
by RobertGonzalez
woger wrote:Just to clarify - the PHP version was 5.0.4
At least that's what phpinfo tells me
Right. The fix, according to the bug tracker, was going to be implemented in 5.1.2. So if your version is older than that, you will need to upgrade.

Posted: Wed Jan 03, 2007 10:22 am
by Kieran Huggins
My previous code will work regardless of PHP version, although it does add a little cruft.