date_sunset vs. date_sun_info

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Herbert Sauerer

    #1

    date_sunset vs. date_sun_info

    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.

    <?php
    $lat = 50;
    $lon = 11;

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

    date_default_ti mezone_set ("CET");
    $now = time();
    echo "today: ". date("d.m.Y H:i:s", $now) . "\n";
    $today_sunrise = date_sunrise($n ow, SUNFUNCS_RET_TI MESTAMP, $lat, $lon);
    $today_sunset = date_sunset($no w, SUNFUNCS_RET_TI MESTAMP, $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
  • Peter H. Coffin

    #2
    Re: date_sunset vs. date_sun_info

    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.
    >
    ><?php
    $lat = 50;
    $lon = 11;
    >
    echo "PHP-Version:" . phpversion() . "\n";
    >
    date_default_ti mezone_set ("CET");
    $now = time();
    echo "today: ". date("d.m.Y H:i:s", $now) . "\n";
    $today_sunrise = date_sunrise($n ow, SUNFUNCS_RET_TI MESTAMP, $lat, $lon);
    $today_sunset = date_sunset($no w, SUNFUNCS_RET_TI MESTAMP, $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.

    <?php
    $sun_info = date_sun_info(s trtotime("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_twilig ht_begin: 17:23:44
    nautical_twilig ht_end: 15:02:01
    astronomical_tw ilight_begin: 18:00:01
    astronomical_tw ilight_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

    Comment

    Working...