ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
TimeZone.php
Go to the documentation of this file.
1 <?php
2 
38 {
39  /*
40  * Default Timezone used for date/time conversions
41  *
42  * @private
43  * @var string
44  */
45  protected static $_timezone = 'UTC';
46 
53  public static function _validateTimeZone($timezone) {
54  if (in_array($timezone, DateTimeZone::listIdentifiers())) {
55  return TRUE;
56  }
57  return FALSE;
58  }
59 
66  public static function setTimeZone($timezone) {
67  if (self::_validateTimezone($timezone)) {
68  self::$_timezone = $timezone;
69  return TRUE;
70  }
71  return FALSE;
72  } // function setTimezone()
73 
74 
80  public static function getTimeZone() {
81  return self::$_timezone;
82  } // function getTimezone()
83 
84 
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;
99  }
100  if (empty($transitions)) {
101  $transitions[] = end($allTransitions);
102  }
103  }
104 
105  return $transitions;
106  }
107 
117  public static function getTimeZoneAdjustment($timezone, $timestamp) {
118  if ($timezone !== NULL) {
119  if (!self::_validateTimezone($timezone)) {
120  throw new PHPExcel_Exception("Invalid timezone " . $timezone);
121  }
122  } else {
123  $timezone = self::$_timezone;
124  }
125 
126  if ($timezone == 'UST') {
127  return 0;
128  }
129 
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);
135  }
136 
137  return (count($transitions) > 0) ? $transitions[0]['offset'] : 0;
138  }
139 
140 }
static getTimeZone()
Return the Default Timezone used for date/time conversions.
Definition: TimeZone.php:80
Create styles array
The data for the language used.
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81
static _validateTimeZone($timezone)
Validate a Timezone name.
Definition: TimeZone.php:53
static getTimeZoneAdjustment($timezone, $timestamp)
Return the Timezone offset used for date/time conversions to/from UST This requires both the timezone...
Definition: TimeZone.php:117
static setTimeZone($timezone)
Set the Default Timezone used for date/time conversions.
Definition: TimeZone.php:66
static _getTimezoneTransitions($objTimezone, $timestamp)
Return the Timezone transition for the specified timezone and timestamp.
Definition: TimeZone.php:92