<?php
/**
* Get an array of human readable times for sun events
* @param \DateTime $date A \DateTime Object set to the desired date
* and the correct timezone for the place in question
* @param float $lat The latitude of the place in question
* @param float $lon The longitude of the place in question
*
* @return array An associative array of human readable times sorted in chronological order.
*/
function adjustedSunInfo(\DateTime $date,$lat,$lon) {
$sinfo=date_sun_info ($date->getTimestamp() ,$lat,$lon );
foreach($sinfo as $key=>$val) {
//You should check that the value isn't 1 or empty first
$time = new \DateTime('@' . $val);
$time->setTimezone($date->getTimeZone());
$sinfo[$key] = $time->format('Y m d H:i:s');
}
asort($sinfo);
return $sinfo;
}
$time = new \DateTime('2013-01-01', new \DateTimeZone('Pacific/Chatham'));
var_dump(adjustedSunInfo($time, -44.5, -176.2));