note 101170 deleted from function.date-sunrise by thiago
| From: | thiago@php.net | Date: | Wed, 01 Dec 2010 12:51:13 +0000 |
| Subject: | note 101170 deleted from function.date-sunrise by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-174521@lists.php.net to get a copy of this message | ||
Note Submitter: peter dot burden at gmail dot com
----
Care should be taken to ensure that time zones and daylight saving are handled correctly when using
these functions.
<?php
$date = new DateTime('2010-12-21'); // Midwinter
$tz = new DateTimeZone("Europe/London");
$date->setTimezone($tz);
$date->setTime(12,0,0);
$t = $date->getTimestamp();
$respr = date_sunrise($t,SUNFUNCS_RET_STRING,52.58,-2.133);
$resps = date_sunset($t,SUNFUNCS_RET_STRING,52.58,-2.133);
echo date("c",$t) . "\n";
echo "Rise = " . $respr . " Set = " . $resps . "\n";
$date->setDate(2010,6,24); // Midsummer
$date->setTime(12,0,0);
$t = $date->getTimestamp();
$respr = date_sunrise($t,SUNFUNCS_RET_STRING,52.58,2.133);
$resps = date_sunset($t,SUNFUNCS_RET_STRING,52.58,2.133);
echo date("c",$t) . "\n";
echo "Rise = " . $respr . " Set = " . $resps . "\n";
?>
which produces the output below (lat/long are for Wolverhampton, England)
2010-12-21T12:00:00+00:00
Rise = 09:17 Set = 16:56
2010-06-24T12:00:00+01:00
Rise = 04:28 Set = 21:19
The figures for June are correct using daylight saving time, the figures for December are 1 hour
late, as if daylight saving time adjustment was still being applied. The two values of $t differ by
180 days and 1 hour as they should. Sunrise and sunset times checked using http://sunrise-sunset.dusk-dawn.com