/** * Converts a Date Time value into the user Timezone if it's different * first convert to UTC then make timezone + daytime conversions * @param timestamp $time : is the system timzone : must be a timestamp like strtotime or time * @param php::timezone $tz is a Php timezone string. If not filled will use userPref or system TZ (if not loggedin) : http://php.net/manual/fr/timezones.php */ public static function applyTimeZone($time, $tz = null, $type = null) { $systemTZ = date_default_timezone_get(); //echo "<br/>xxxxxxx applyTimeZone input time : ".date("Y-m-d H:i:s", $time); if (!$tz) { $tz = UserPref::getValue(UserPref::PREF_USER_TIME_ZONE); } if (!DateHelper::isEmptyDate($time)) { if (date_default_timezone_get() != $tz) { //pass the time to UTC timezone //date_default_timezone_set("UTC"); //$utcTime = date("Y-m-d H:i", $time); //$utcTime = strtotime($utcTime); //now tranform back to User timezone /*Yii::app()->localtime->TimeZone = $tz; $return = array('datetime' => Yii::app()->localtime->toLocalDateTime(date('Y-m-d H:i:s',$utcTime),'short','short'), 'date' => Yii::app()->localtime->toLocalDate(date('Y-m-d H:i:s',$utcTime),'short','short'), 'time' => Yii::app()->localtime->toLocalTime(date('Y-m-d H:i:s',$utcTime),'short','short'));*/ date_default_timezone_set($tz); } $return = array('datetime' => date(self::DATETIME_FORMAT, $time), 'date' => date("Y-m-d", $time), 'time' => date("H:i", $time), 'timestamp' => $time, 'iso8601' => date('Ymd', $time) . 'T' . date('His', $time) . ($tz == 'UTC' ? 'Z' : '')); //echo "<br/>xxxxxxx applyTimeZone output time : ".$return['datetime']; } else { $return = null; } date_default_timezone_set($systemTZ); return $type != null ? $return[$type] : $return; }