ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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.

@access private

Parameters
stringvalid timezone

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

66 {
67 global $ilLog;
68
69 $this->log = $ilLog;
70
71 if ($a_timezone) {
72 $this->timezone = $a_timezone;
73 } else {
74 $this->timezone = self::_getDefaultTimeZone();
75 }
76
77 if (!self::$server_timezone) {
78 self::$server_timezone = self::_getDefaultTimeZone();
79 }
80
81 if (!self::$default_timezone) {
83 }
84 }
static _getDefaultTimeZone()
Calculate and set default time zone.

References $ilLog, and _getDefaultTimeZone().

+ Here is the call graph for this function:

Member Function Documentation

◆ __sleep()

ilTimeZone::__sleep ( )

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

87 {
88 return array('timezone');
89 }

◆ __wakeup()

ilTimeZone::__wakeup ( )

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

92 {
93 global $ilLog;
94
95 $this->log = $ilLog;
96 }

References $ilLog.

◆ _getDefaultTimeZone()

static ilTimeZone::_getDefaultTimeZone ( )
static

Calculate and set default time zone.

@access public

Returns
time zone string

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

267 {
268 if (strlen(self::$default_timezone)) {
270 }
271 // PHP >= 5.2.0
272 // php throws a warning date_default_timezone_get relies on os determination. There is no way to check if this could happen.
273 if (function_exists('date_default_timezone_get') and $tz = @date_default_timezone_get()) {
274 return self::$default_timezone = $tz;
275 }
276 // PHP ini option (PHP >= 5.1.0)
277 if ($tz = ini_get('date.timezone')) {
278 return self::$default_timezone = $tz;
279 }
280 // is $_ENV['PHP_TZ'] set ?
281 if ($tz = getenv('PHP_TZ')) {
282 return self::$default_timezone = $tz;
283 }
284 // is $_ENV['TZ'] set ?
285 if ($tz = getenv('TZ')) {
286 return self::$default_timezone = $tz;
287 }
288 if (strlen($tz = date('T'))) {
289 return self::$default_timezone = $tz;
290 }
291 return self::$default_timezone = self::UTC;
292 }
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
static $default_timezone

References $default_timezone, $tz, date, and UTC.

Referenced by ilSoapInstallationInfoXMLWriter\__buildClient(), __construct(), _getInstance(), _setDefaultTimeZone(), initDefaultTimeZone(), ilObjCalendarSettingsGUI\initFormSettings(), and ilCalendarSettings\read().

+ Here is the caller graph for this function:

◆ _getInstance()

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

get instance by timezone

@access public

Parameters
stringvalid php timezone
Exceptions
ilTimeZoneException

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

119 {
120 global $ilLog;
121
122 if (!$a_tz) {
124 }
125
126 if (isset(self::$instances[$a_tz])) {
127 $instance = self::$instances[$a_tz];
128 } else {
129 $instance = self::$instances[$a_tz] = new ilTimeZone($a_tz);
130 }
131
132 // Validate timezone if it is not validated before
133 if (!array_key_exists($instance->getIdentifier(), self::$valid_tz)) {
134 if (!$instance->validateTZ()) {
135 throw new ilTimeZoneException('Unsupported timezone given.');
136 }
137 self::$valid_tz[$instance->getIdentifier()] = true;
138 }
139
140 // now validate timezone setting
141 return $instance;
142 }
Class for TimeZone exceptions.
This class offers methods for timezone handling.

References $ilLog, and _getDefaultTimeZone().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _restoreDefaultTimeZone()

static ilTimeZone::_restoreDefaultTimeZone ( )
static

restore default timezone to server timezone

@access public

Parameters

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

254 {
255 self::$default_timezone = self::$server_timezone;
256 self::_switchTimeZone(self::$default_timezone);
257 }
static _switchTimeZone($a_timezone)
Switch tz.
static $server_timezone

References $server_timezone, and _switchTimeZone().

Referenced by ilCalendarRecurrenceCalculator\calculateDateList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _setDefaultTimeZone()

static ilTimeZone::_setDefaultTimeZone (   $a_tz)
static

set default timezone

@access public

Parameters

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

236 {
237 // Save the server timezone, since there is no way to read later.
238 if (!self::$server_timezone) {
239 self::$server_timezone = self::_getDefaultTimeZone();
240 }
241
242 self::$default_timezone = $a_tz;
243 }

References _getDefaultTimeZone().

Referenced by ilCalendarRecurrenceCalculator\adjustTimeZones().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _switchTimeZone()

static ilTimeZone::_switchTimeZone (   $a_timezone)
staticprotected

Switch tz.

@access public

Exceptions
ilTimeZoneException

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

201 {
202 global $ilLog;
203
204 if (self::$current_timezone == $a_timezone) {
205 #$ilLog->write(__METHOD__.': Do not switch to active timezone: '.$a_timezone);
206 return true;
207 }
208
209 // PHP >= 5.2.0
210 if (function_exists('date_default_timezone_set')) {
211 if (!date_default_timezone_set($a_timezone)) {
212 $ilLog->write(__METHOD__ . ': Invalid timezone given. Timezone: ' . $a_timezone);
213 throw new ilTimeZoneException('Invalid timezone given');
214 }
215 #$ilLog->write(__METHOD__.': Switched timezone to: '.$a_timezone);
216 self::$current_timezone = $a_timezone;
217 return true;
218 }
219 if (!putenv('TZ=' . $a_timezone)) {
220 $ilLog->write(__METHOD__ . ': Cannot set TZ environment variable. Please register TZ in php.ini (safe_mode_allowed_env_vars). Timezone');
221 throw new ilTimeZoneException('Cannot set TZ environment variable.');
222 }
223 self::$current_timezone = $a_timezone;
224 return true;
225 }

References $ilLog.

Referenced by _restoreDefaultTimeZone(), restoreTZ(), and switchTZ().

+ Here is the caller graph for this function:

◆ getIdentifier()

ilTimeZone::getIdentifier ( )

get identifier

@access public

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

105 {
106 return $this->timezone;
107 }

References $timezone.

◆ initDefaultTimeZone()

static ilTimeZone::initDefaultTimeZone ( ilIniFile  $ini)
static

Initialize default timezone from system settings.

Returns
bool

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

299 {
300 $tz = $ini->readVariable('server', 'timezone');
301 if (!strlen($tz)) {
303 }
304 if (!strlen($tz)) {
305 $tz = 'UTC';
306 }
307 date_default_timezone_set($tz);
308 return $tz;
309 }
$ini
Definition: raiseError.php:4

References $ini, $tz, and _getDefaultTimeZone().

Referenced by ilInitialisation\initIliasIniFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ restoreTZ()

ilTimeZone::restoreTZ ( )

Restore default timezone.

@access public

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

167 {
168 try {
169 self::_switchTimeZone(self::$default_timezone);
170 return true;
171 } catch (ilTimeZoneException $e) {
172 // Shouldn't happen since this has been checked during initialisation
173 $this->log->write(__METHOD__ . ': Unsupported timezone given: Timzone: ' . $this->timezone);
174 return false;
175 }
176 }

References _switchTimeZone().

Referenced by validateTZ().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ switchTZ()

ilTimeZone::switchTZ ( )

Switch timezone to given timezone.

@access public

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

150 {
151 try {
152 self::_switchTimeZone($this->timezone);
153 return true;
154 } catch (ilTimeZoneException $exc) {
155 // Shouldn't happen since this has been checked during initialisation
156 $this->log->write(__METHOD__ . ': Unsupported timezone given: Timzone: ' . $this->timezone);
157 return false;
158 }
159 }

References _switchTimeZone().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validateTZ()

ilTimeZone::validateTZ ( )

validate timezone

@access public

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

185 {
186 // this is done by switching to the current tz
187 if ($this->switchTZ() and $this->restoreTZ()) {
188 return true;
189 }
190 return false;
191 }
restoreTZ()
Restore default timezone.
switchTZ()
Switch timezone to given timezone.

References restoreTZ(), and switchTZ().

+ 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.

Referenced by _getDefaultTimeZone().

◆ $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.

Referenced by _restoreDefaultTimeZone().

◆ $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: