note 113678 added to datetimezone.gettransitions

From: Date: Thu, 14 Nov 2013 17:06:48 +0000
Subject: note 113678 added to datetimezone.gettransitions
Groups: php.notes 
Request: Send a blank email to php-notes+get-197523@lists.php.net to get a copy of this message
This will work in PHP_VERSION < 5.3: <?php /** 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, '5.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 29th element is 1980-04-06 // change this in your timezone $first_regular_index=29; $first_regular_year=1980; $transitions = $timeZone->getTransitions(); $index=($year-$first_regular_year)*2+$first_regular_index; } return array_slice($transitions, $index, 2); } ---- Server IP: 192.41.45.150 Probable Submitter: 92.227.2.38 ---- Manual Page -- http://php.net/manual/en/datetimezone.gettransitions.php Edit -- https://master.php.net/note/edit/113678 Del: integrated -- https://master.php.net/note/delete/113678/integrated Del: useless -- https://master.php.net/note/delete/113678/useless Del: bad code -- https://master.php.net/note/delete/113678/bad+code Del: spam -- https://master.php.net/note/delete/113678/spam Del: non-english -- https://master.php.net/note/delete/113678/non-english Del: in docs -- https://master.php.net/note/delete/113678/in+docs Del: other reasons-- https://master.php.net/note/delete/113678 Reject -- https://master.php.net/note/reject/113678 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#197523) next »