note 113671 added to datetimezone.gettransitions
| From: | rubo77 | Date: | Thu, 14 Nov 2013 05:33:53 +0000 |
| Subject: | note 113671 added to datetimezone.gettransitions | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-197513@lists.php.net to get a copy of this message | ||
/** 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);
}
----
Server IP: 72.52.91.14
Probable Submitter: 72.52.91.14
----
Manual Page -- http://php.net/manual/en/datetimezone.gettransitions.php
Edit -- https://master.php.net/note/edit/113671
Del: integrated -- https://master.php.net/note/delete/113671/integrated
Del: useless -- https://master.php.net/note/delete/113671/useless
Del: bad code -- https://master.php.net/note/delete/113671/bad+code
Del: spam -- https://master.php.net/note/delete/113671/spam
Del: non-english -- https://master.php.net/note/delete/113671/non-english
Del: in docs -- https://master.php.net/note/delete/113671/in+docs
Del: other reasons-- https://master.php.net/note/delete/113671
Reject -- https://master.php.net/note/reject/113671
Search -- https://master.php.net/manage/user-notes.php