ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilTimeZone Class Reference

This class offers methods for timezone handling. More...

+ Collaboration diagram for ilTimeZone:

Public Member Functions

 __sleep ()
 
 __wakeup ()
 
 getIdentifier ()
 get identifier More...
 
 switchTZ ()
 Switch timezone to given timezone. More...
 
 restoreTZ ()
 Restore default timezone. More...
 
 validateTZ ()
 validate timezone More...
 

Static Public Member Functions

static _getInstance ($a_tz='')
 get instance by timezone More...
 
static _setDefaultTimeZone ($a_tz)
 set default timezone More...
 
static _restoreDefaultTimeZone ()
 restore default timezone to server timezone More...
 
static _getDefaultTimeZone ()
 Calculate and set default time zone. More...
 
static initDefaultTimeZone (ilIniFile $ini)
 Initialize default timezone from system settings. More...
 

Data Fields

const UTC = 'UTC'
 

Static Public Attributes

static $instances = array()
 
static $valid_tz = array()
 

Static Protected Member Functions

static _switchTimeZone ($a_timezone)
 Switch tz. More...
 

Protected Attributes

 $log
 
 $timezone = "UTC"
 

Static Protected Attributes

static $default_timezone = ''
 
static $current_timezone = ''
 
static $server_timezone = ''
 

Private Member Functions

 __construct ($a_timezone)
 Create new timezone object If no timezone is given, the default server timezone is chosen. More...
 

Detailed Description

This class offers methods for timezone handling.

ilTimeZone::_getDefault tries to "guess" the server timezone in the following manner: 1) PHP >= 5.2.0 use date_default_timezone_get 2) Read ini option date.timezone if available 3) Read environment PHP_TZ 4) Read environment TZ 5) Use date('T') 6) Use UTC

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 43 of file class.ilTimeZone.php.

Constructor & Destructor Documentation

◆ __construct()

ilTimeZone::__construct (   $a_timezone)
private

Create new timezone object If no timezone is given, the default server timezone is chosen.

private

Parameters
stringvalid timezone

Definition at line 65 of file class.ilTimeZone.php.

References $ilLog, and timezone.

66  {
67  global $ilLog;
68 
69  $this->log = $ilLog;
70 
71  if($a_timezone)
72  {
73  $this->timezone = $a_timezone;
74  }
75  else
76  {
77  $this->timezone = self::_getDefaultTimeZone();
78  }
79 
80  if(!self::$server_timezone)
81  {
82  self::$server_timezone = self::_getDefaultTimeZone();
83  }
84 
85  if(!self::$default_timezone)
86  {
87  self::_getDefaultTimeZone();
88  }
89  }
Set timezone

Member Function Documentation

◆ __sleep()

ilTimeZone::__sleep ( )

Definition at line 91 of file class.ilTimeZone.php.

References array.

92  {
93  return array('timezone');
94  }
Create styles array
The data for the language used.

◆ __wakeup()

ilTimeZone::__wakeup ( )

Definition at line 96 of file class.ilTimeZone.php.

References $ilLog.

97  {
98  global $ilLog;
99 
100  $this->log = $ilLog;
101  }

◆ _getDefaultTimeZone()

static ilTimeZone::_getDefaultTimeZone ( )
static

Calculate and set default time zone.

public

Returns
time zone string

Definition at line 289 of file class.ilTimeZone.php.

References $tz, and date.

Referenced by ilSoapInstallationInfoXMLWriter\__buildClient(), ilObjCalendarSettingsGUI\initFormSettings(), and ilCalendarSettings\read().

290  {
291  if(strlen(self::$default_timezone))
292  {
293  return self::$default_timezone;
294  }
295  // PHP >= 5.2.0
296  // php throws a warning date_default_timezone_get relies on os determination. There is no way to check if this could happen.
297  if(function_exists('date_default_timezone_get') and $tz = @date_default_timezone_get())
298  {
299  return self::$default_timezone = $tz;
300  }
301  // PHP ini option (PHP >= 5.1.0)
302  if($tz = ini_get('date.timezone'))
303  {
304  return self::$default_timezone = $tz;
305  }
306  // is $_ENV['PHP_TZ'] set ?
307  if($tz = getenv('PHP_TZ'))
308  {
309  return self::$default_timezone = $tz;
310  }
311  // is $_ENV['TZ'] set ?
312  if($tz = getenv('TZ'))
313  {
314  return self::$default_timezone = $tz;
315  }
316  if(strlen($tz = date('T')))
317  {
318  return self::$default_timezone = $tz;
319  }
320  return self::$default_timezone = self::UTC;
321  }
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
+ Here is the caller graph for this function:

◆ _getInstance()

static ilTimeZone::_getInstance (   $a_tz = '')
static

get instance by timezone

public

Parameters
stringvalid php timezone
Exceptions
ilTimeZoneException

Definition at line 123 of file class.ilTimeZone.php.

References $ilLog.

Referenced by ilDate\__construct(), ilDateTime\__construct(), ilCalendarRecurrenceCalculator\applyBYMONTHDAYRules(), ilDateTime\get(), ilICalParser\getTZ(), ilICalParser\parse(), ilDateTime\switchTimeZone(), and ilUserImportParser\verifyPref().

124  {
125  global $ilLog;
126 
127  if(!$a_tz)
128  {
129  $a_tz = self::_getDefaultTimeZone();
130  }
131 
132  if(isset(self::$instances[$a_tz]))
133  {
134  $instance = self::$instances[$a_tz];
135  }
136  else
137  {
138  $instance = self::$instances[$a_tz] = new ilTimeZone($a_tz);
139  }
140 
141  // Validate timezone if it is not validated before
142  if(!array_key_exists($instance->getIdentifier(),self::$valid_tz))
143  {
144  if(!$instance->validateTZ())
145  {
146  throw new ilTimeZoneException('Unsupported timezone given.');
147  }
148  self::$valid_tz[$instance->getIdentifier()] = true;
149  }
150 
151  // now validate timezone setting
152  return $instance;
153  }
This class offers methods for timezone handling.
Class for TimeZone exceptions.
+ Here is the caller graph for this function:

◆ _restoreDefaultTimeZone()

static ilTimeZone::_restoreDefaultTimeZone ( )
static

restore default timezone to server timezone

public

Parameters

Definition at line 276 of file class.ilTimeZone.php.

Referenced by ilCalendarRecurrenceCalculator\calculateDateList().

277  {
278  self::$default_timezone = self::$server_timezone;
279  self::_switchTimeZone(self::$default_timezone);
280  }
+ Here is the caller graph for this function:

◆ _setDefaultTimeZone()

static ilTimeZone::_setDefaultTimeZone (   $a_tz)
static

set default timezone

public

Parameters

Definition at line 257 of file class.ilTimeZone.php.

Referenced by ilCalendarRecurrenceCalculator\adjustTimeZones().

258  {
259  // Save the server timezone, since there is no way to read later.
260  if(!self::$server_timezone)
261  {
262  self::$server_timezone = self::_getDefaultTimeZone();
263  }
264 
265  self::$default_timezone = $a_tz;
266  }
+ Here is the caller graph for this function:

◆ _switchTimeZone()

static ilTimeZone::_switchTimeZone (   $a_timezone)
staticprotected

Switch tz.

public

Exceptions
ilTimeZoneException

Definition at line 218 of file class.ilTimeZone.php.

References $ilLog.

219  {
220  global $ilLog;
221 
222  if(self::$current_timezone == $a_timezone)
223  {
224  #$ilLog->write(__METHOD__.': Do not switch to active timezone: '.$a_timezone);
225  return true;
226  }
227 
228  // PHP >= 5.2.0
229  if(function_exists('date_default_timezone_set'))
230  {
231  if(!date_default_timezone_set($a_timezone))
232  {
233  $ilLog->write(__METHOD__.': Invalid timezone given. Timezone: '.$a_timezone);
234  throw new ilTimeZoneException('Invalid timezone given');
235  }
236  #$ilLog->write(__METHOD__.': Switched timezone to: '.$a_timezone);
237  self::$current_timezone = $a_timezone;
238  return true;
239  }
240  if(!putenv('TZ='.$a_timezone))
241  {
242  $ilLog->write(__METHOD__.': Cannot set TZ environment variable. Please register TZ in php.ini (safe_mode_allowed_env_vars). Timezone');
243  throw new ilTimeZoneException('Cannot set TZ environment variable.');
244  }
245  self::$current_timezone = $a_timezone;
246  return true;
247  }
Class for TimeZone exceptions.

◆ getIdentifier()

ilTimeZone::getIdentifier ( )

get identifier

public

Definition at line 109 of file class.ilTimeZone.php.

References $timezone.

110  {
111  return $this->timezone;
112  }

◆ initDefaultTimeZone()

static ilTimeZone::initDefaultTimeZone ( ilIniFile  $ini)
static

Initialize default timezone from system settings.

Returns
bool

Definition at line 327 of file class.ilTimeZone.php.

References $tz, and ilIniFile\readVariable().

Referenced by ilInitialisation\initIliasIniFile().

328  {
329  $tz = $ini->readVariable('server','timezone');
330  if(!strlen($tz))
331  {
332  $tz = self::_getDefaultTimeZone();
333  }
334  if(!strlen($tz))
335  {
336  $tz = 'UTC';
337  }
338  date_default_timezone_set($tz);
339  return $tz;
340  }
readVariable($a_group, $a_var_name)
reads a single variable from a group public
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ restoreTZ()

ilTimeZone::restoreTZ ( )

Restore default timezone.

public

Definition at line 180 of file class.ilTimeZone.php.

Referenced by validateTZ().

181  {
182  try
183  {
184  self::_switchTimeZone(self::$default_timezone);
185  return true;
186  }
187  catch(ilTimeZoneException $e)
188  {
189  // Shouldn't happen since this has been checked during initialisation
190  $this->log->write(__METHOD__.': Unsupported timezone given: Timzone: '.$this->timezone);
191  return false;
192  }
193  }
Class for TimeZone exceptions.
+ Here is the caller graph for this function:

◆ switchTZ()

ilTimeZone::switchTZ ( )

Switch timezone to given timezone.

public

Definition at line 160 of file class.ilTimeZone.php.

References timezone.

Referenced by ilICalParser\switchTZ(), and validateTZ().

161  {
162  try
163  {
164  self::_switchTimeZone($this->timezone);
165  return true;
166  }
167  catch(ilTimeZoneException $exc)
168  {
169  // Shouldn't happen since this has been checked during initialisation
170  $this->log->write(__METHOD__.': Unsupported timezone given: Timzone: '.$this->timezone);
171  return false;
172  }
173  }
Set timezone
Class for TimeZone exceptions.
+ Here is the caller graph for this function:

◆ validateTZ()

ilTimeZone::validateTZ ( )

validate timezone

public

Definition at line 201 of file class.ilTimeZone.php.

References restoreTZ(), and switchTZ().

202  {
203  // this is done by switching to the current tz
204  if($this->switchTZ() and $this->restoreTZ())
205  {
206  return true;
207  }
208  return false;
209  }
switchTZ()
Switch timezone to given timezone.
restoreTZ()
Restore default timezone.
+ Here is the call graph for this function:

Field Documentation

◆ $current_timezone

ilTimeZone::$current_timezone = ''
staticprotected

Definition at line 51 of file class.ilTimeZone.php.

◆ $default_timezone

ilTimeZone::$default_timezone = ''
staticprotected

Definition at line 50 of file class.ilTimeZone.php.

◆ $instances

ilTimeZone::$instances = array()
static

Definition at line 47 of file class.ilTimeZone.php.

◆ $log

ilTimeZone::$log
protected

Definition at line 54 of file class.ilTimeZone.php.

◆ $server_timezone

ilTimeZone::$server_timezone = ''
staticprotected

Definition at line 52 of file class.ilTimeZone.php.

◆ $timezone

ilTimeZone::$timezone = "UTC"
protected

Definition at line 55 of file class.ilTimeZone.php.

Referenced by getIdentifier().

◆ $valid_tz

ilTimeZone::$valid_tz = array()
static

Definition at line 48 of file class.ilTimeZone.php.

◆ UTC


The documentation for this class was generated from the following file: