date_sunset vs. date_sun_info

date_sunset vs. date_sun_info

am 14.04.2008 22:03:32 von Herbert Sauerer

Hello,

can anybody tell me, what's wrong with tis code? date_sunset() and
date_sun_info() return totally different values for the same time and
location.

$lat = 50;
$lon = 11;

echo "PHP-Version:" . phpversion() . "\n";

date_default_timezone_set ("CET");
$now = time();
echo "today: ". date("d.m.Y H:i:s", $now) . "\n";
$today_sunrise = date_sunrise($now, SUNFUNCS_RET_TIMESTAMP, $lat, $lon);
$today_sunset = date_sunset($now, SUNFUNCS_RET_TIMESTAMP, $lat, $lon);

echo "Sunrise 1: " . date("H:i:s", $today_sunrise) . "\n";
echo "Sunset 1: " . date("H:i:s", $today_sunset) . " \n";

$sun_info = date_sun_info($now , $lat, $lon);
echo "Sunrise 2: ". date("H:i:s", $sun_info['sunrise']) . " \n";
echo "Sunset 2: ". date("H:i:s", $sun_info['sunset']) . " \n";
?>

And the output:
PHP-Version:5.1.4
today: 14.04.2008 22:59:11
Sunrise 1: 06:23:09
Sunset 1: 20:09:01
Sunrise 2: 04:28:57
Sunset 2: 16:51:16

TIA and greetings,
Herbert

Re: date_sunset vs. date_sun_info

am 15.04.2008 14:57:51 von hellsop

On Mon, 14 Apr 2008 22:03:32 +0200, Herbert Sauerer wrote:
> Hello,
>
> can anybody tell me, what's wrong with tis code? date_sunset() and
> date_sun_info() return totally different values for the same time and
> location.
>
> > $lat = 50;
> $lon = 11;
>
> echo "PHP-Version:" . phpversion() . "\n";
>
> date_default_timezone_set ("CET");
> $now = time();
> echo "today: ". date("d.m.Y H:i:s", $now) . "\n";
> $today_sunrise = date_sunrise($now, SUNFUNCS_RET_TIMESTAMP, $lat, $lon);
> $today_sunset = date_sunset($now, SUNFUNCS_RET_TIMESTAMP, $lat, $lon);
>
> echo "Sunrise 1: " . date("H:i:s", $today_sunrise) . "\n";
> echo "Sunset 1: " . date("H:i:s", $today_sunset) . " \n";
>
> $sun_info = date_sun_info($now , $lat, $lon);
> echo "Sunrise 2: ". date("H:i:s", $sun_info['sunrise']) . " \n";
> echo "Sunset 2: ". date("H:i:s", $sun_info['sunset']) . " \n";
> ?>
>
> And the output:
> PHP-Version:5.1.4
> today: 14.04.2008 22:59:11
> Sunrise 1: 06:23:09
> Sunset 1: 20:09:01
> Sunrise 2: 04:28:57
> Sunset 2: 16:51:16

Using a timezone of "America/Chicago" and the lat/long of Navy Pier in
Chicago as being about

$lat = 41.9;
$lon = -87.6;

gives back the following results.

PHP-Version:5.1.6
today: 15.04.2008 07:41:31
Sunrise 1: 06:07:31
Sunset 1: 19:32:18
Sunrise 2: 18:00:00
Sunset 2: 18:00:00

Here's the example from the manual with the lat/lon from the center of
the 60606 postal code, and today's date.

$sun_info = date_sun_info(strtotime("2008-04-14"), 41.79 , -87.75);
foreach ($sun_info as $key => $val) {
echo "$key: " . date("H:i:s", $val) . "\n";
}

sunrise: 18:00:00
sunset: 18:00:00
transit: 04:12:52
civil_twilight_begin: 18:00:00
civil_twilight_end: 18:00:00
nautical_twilight_begin: 17:23:44
nautical_twilight_end: 15:02:01
astronomical_twilight_begin: 18:00:01
astronomical_twilight_end: 18:00:01

The groups of functions agree for longitudes fairly close to zero, but
date_sun_info() seems to fail further out.

--
Don't even get me started on the MCSEs I know. It's a miracle of
modern technology that some of these fsckwits still draw breath,
much less a paycheck.
-- Marc Bowden