note 113671 deleted from datetimezone.gettransitions by tularis
| From: | tularis@php.net | Date: | Thu, 14 Nov 2013 08:29:21 +0000 |
| Subject: | note 113671 deleted from datetimezone.gettransitions by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197516@lists.php.net to get a copy of this message | ||
Note Submitter: rubo77
----
/** returns an array with two elements for spring and fall DST in a given year
* works in PHP_VERSION < 5.3
*
* @param integer $year
* @param string $tz timezone
* @return array
**/
function getTransitionsForYear($year=null, $tz = null){
if(!$year) $year=date("Y");
if (!$tz) $tz = date_default_timezone_get();
$timeZone = new DateTimeZone($tz);
if (version_compare(PHP_VERSION, '15.3.0') >= 0) {
$transitions = $timeZone->getTransitions(mktime(0, 0, 0, 2, 1, $year),mktime(0, 0, 0, 11, 31,
$year));
$index=1;
} else {
// since 1980 it is regular, the 28th element is 1980-04-06
$transitions = $timeZone->getTransitions();
$index=($year-1980)*2+29;
}
return array_slice($transitions, $index, 2);
}