473,387 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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_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
Jun 2 '08 #1
1 2795
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_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.

<?php
$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
Jun 2 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Your Name | last post by:
I'm trying to use date_sunrise() and date_sunset() functions in my php5 code. I use them as follows: date_default_timezone_set("America/New_York"); $sr =...
1
by: Denis McMahon | last post by:
I'm assuming that in php.ini, date.default_latitude is +ve North of the equator and -ve South, but what about date.default_longitude? -ve West and +ve East of Greenwich? or vice-versa? I know...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.