Updated gui for user facility settings (#1327)
[openemr.git] / vendor / phpoffice / phpexcel / Classes / PHPExcel / Shared / TimeZone.php
blob1792a295389bbfe59b5a2a22bc72b50d49ec3ecc
1 <?php
3 /**
4 * PHPExcel
6 * Copyright (c) 2006 - 2014 PHPExcel
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 * @category PHPExcel
23 * @package PHPExcel_Shared
24 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
25 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26 * @version ##VERSION##, ##DATE##
30 /**
31 * PHPExcel_Shared_TimeZone
33 * @category PHPExcel
34 * @package PHPExcel_Shared
35 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
37 class PHPExcel_Shared_TimeZone
40 * Default Timezone used for date/time conversions
42 * @private
43 * @var string
45 protected static $_timezone = 'UTC';
47 /**
48 * Validate a Timezone name
50 * @param string $timezone Time zone (e.g. 'Europe/London')
51 * @return boolean Success or failure
53 public static function _validateTimeZone($timezone) {
54 if (in_array($timezone, DateTimeZone::listIdentifiers())) {
55 return TRUE;
57 return FALSE;
60 /**
61 * Set the Default Timezone used for date/time conversions
63 * @param string $timezone Time zone (e.g. 'Europe/London')
64 * @return boolean Success or failure
66 public static function setTimeZone($timezone) {
67 if (self::_validateTimezone($timezone)) {
68 self::$_timezone = $timezone;
69 return TRUE;
71 return FALSE;
72 } // function setTimezone()
75 /**
76 * Return the Default Timezone used for date/time conversions
78 * @return string Timezone (e.g. 'Europe/London')
80 public static function getTimeZone() {
81 return self::$_timezone;
82 } // function getTimezone()
85 /**
86 * Return the Timezone transition for the specified timezone and timestamp
88 * @param DateTimeZone $objTimezone The timezone for finding the transitions
89 * @param integer $timestamp PHP date/time value for finding the current transition
90 * @return array The current transition details
92 private static function _getTimezoneTransitions($objTimezone, $timestamp) {
93 $allTransitions = $objTimezone->getTransitions();
94 $transitions = array();
95 foreach($allTransitions as $key => $transition) {
96 if ($transition['ts'] > $timestamp) {
97 $transitions[] = ($key > 0) ? $allTransitions[$key - 1] : $transition;
98 break;
100 if (empty($transitions)) {
101 $transitions[] = end($allTransitions);
105 return $transitions;
109 * Return the Timezone offset used for date/time conversions to/from UST
110 * This requires both the timezone and the calculated date/time to allow for local DST
112 * @param string $timezone The timezone for finding the adjustment to UST
113 * @param integer $timestamp PHP date/time value
114 * @return integer Number of seconds for timezone adjustment
115 * @throws PHPExcel_Exception
117 public static function getTimeZoneAdjustment($timezone, $timestamp) {
118 if ($timezone !== NULL) {
119 if (!self::_validateTimezone($timezone)) {
120 throw new PHPExcel_Exception("Invalid timezone " . $timezone);
122 } else {
123 $timezone = self::$_timezone;
126 if ($timezone == 'UST') {
127 return 0;
130 $objTimezone = new DateTimeZone($timezone);
131 if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
132 $transitions = $objTimezone->getTransitions($timestamp,$timestamp);
133 } else {
134 $transitions = self::_getTimezoneTransitions($objTimezone, $timestamp);
137 return (count($transitions) > 0) ? $transitions[0]['offset'] : 0;