note 113672 added to datetimezone.gettransitions

From: Date: Thu, 14 Nov 2013 05:36:45 +0000
Subject: note 113672 added to datetimezone.gettransitions
Groups: php.notes 
Request: Send a blank email to php-notes+get-197514@lists.php.net to get a copy of this message
This will work in PHP < 5.3 /** 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 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/113672 Del: integrated -- https://master.php.net/note/delete/113672/integrated Del: useless -- https://master.php.net/note/delete/113672/useless Del: bad code -- https://master.php.net/note/delete/113672/bad+code Del: spam -- https://master.php.net/note/delete/113672/spam Del: non-english -- https://master.php.net/note/delete/113672/non-english Del: in docs -- https://master.php.net/note/delete/113672/in+docs Del: other reasons-- https://master.php.net/note/delete/113672 Reject -- https://master.php.net/note/reject/113672 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#197514) next »