ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilTimeZone Class Reference

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

+ Collaboration diagram for ilTimeZone:

Public Member Functions

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

Static Public Member Functions

static _getInstance ($a_tz= '')
 get instance by timezone
static _setDefaultTimeZone ($a_tz)
 set default timezone
static _restoreDefaultTimeZone ()
 restore default timezone to server timezone
static _getDefaultTimeZone ()
 Calculate and set default time zone.

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.

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.

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

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 _getDefaultTimeZone().

{
global $ilLog;
$this->log = $ilLog;
if($a_timezone)
{
$this->timezone = $a_timezone;
}
else
{
$this->timezone = self::_getDefaultTimeZone();
}
if(!self::$server_timezone)
{
self::$server_timezone = self::_getDefaultTimeZone();
}
if(!self::$default_timezone)
{
}
}

+ Here is the call graph for this function:

Member Function Documentation

static ilTimeZone::_getDefaultTimeZone ( )
static

Calculate and set default time zone.

public

Returns
time zone string

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

References $default_timezone, and UTC.

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

{
if(strlen(self::$default_timezone))
{
}
// PHP >= 5.2.0
if(function_exists('date_default_timezone_get') and $tz = date_default_timezone_get())
{
return self::$default_timezone = $tz;
}
// PHP ini option (PHP >= 5.1.0)
if($tz = ini_get('date.timezone'))
{
return self::$default_timezone = $tz;
}
// is $_ENV['PHP_TZ'] set ?
if($tz = getenv('PHP_TZ'))
{
return self::$default_timezone = $tz;
}
// is $_ENV['TZ'] set ?
if($tz = getenv('TZ'))
{
return self::$default_timezone = $tz;
}
if(strlen($tz = date('T')))
{
return self::$default_timezone = $tz;
}
return self::$default_timezone = self::UTC;
}

+ Here is the caller graph for this function:

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

get instance by timezone

public

Parameters
stringvalid php timezone
Exceptions
ilTimeZoneException

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

References $ilLog, $valid_tz, and _getDefaultTimeZone().

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

{
global $ilLog;
if(!$a_tz)
{
}
if(isset(self::$instances[$a_tz]))
{
$instance = self::$instances[$a_tz];
}
else
{
$instance = self::$instances[$a_tz] = new ilTimeZone($a_tz);
}
// Validate timezone if it is not validated before
if(!array_key_exists($instance->getIdentifier(),self::$valid_tz))
{
if(!$instance->validateTZ())
{
throw new ilTimeZoneException('Unsupported timezone given.');
}
self::$valid_tz[$instance->getIdentifier()] = true;
}
// now validate timezone setting
return $instance;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilTimeZone::_restoreDefaultTimeZone ( )
static

restore default timezone to server timezone

public

Parameters

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

References $server_timezone, and _switchTimeZone().

Referenced by ilCalendarRecurrenceCalculator\calculateDateList().

{
self::$default_timezone = self::$server_timezone;
self::_switchTimeZone(self::$default_timezone);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilTimeZone::_setDefaultTimeZone (   $a_tz)
static

set default timezone

public

Parameters

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

References _getDefaultTimeZone().

Referenced by ilCalendarRecurrenceCalculator\adjustTimeZones().

{
// Save the server timezone, since there is no way to read later.
if(!self::$server_timezone)
{
self::$server_timezone = self::_getDefaultTimeZone();
}
self::$default_timezone = $a_tz;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilTimeZone::_switchTimeZone (   $a_timezone)
staticprotected

Switch tz.

public

Exceptions
ilTimeZoneException

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

References $ilLog.

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

{
global $ilLog;
if(self::$current_timezone == $a_timezone)
{
#$ilLog->write(__METHOD__.': Do not switch to active timezone: '.$a_timezone);
return true;
}
// PHP >= 5.2.0
if(function_exists('date_default_timezone_set'))
{
if(!date_default_timezone_set($a_timezone))
{
$ilLog->write(__METHOD__.': Invalid timezone given. Timezone: '.$a_timezone);
throw new ilTimeZoneException('Invalid timezone given');
}
#$ilLog->write(__METHOD__.': Switched timezone to: '.$a_timezone);
self::$current_timezone = $a_timezone;
return true;
}
if(!putenv('TZ='.$a_timezone))
{
$ilLog->write(__METHOD__.': Cannot set TZ environment variable. Please register TZ in php.ini (safe_mode_allowed_env_vars). Timezone');
throw new ilTimeZoneException('Cannot set TZ environment variable.');
}
self::$current_timezone = $a_timezone;
return true;
}

+ Here is the caller graph for this function:

ilTimeZone::getIdentifier ( )

get identifier

public

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

References $timezone.

{
}
ilTimeZone::restoreTZ ( )

Restore default timezone.

public

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

References _switchTimeZone().

Referenced by validateTZ().

{
try
{
self::_switchTimeZone(self::$default_timezone);
return true;
}
{
// Shouldn't happen since this has been checked during initialisation
$this->log->write(__METHOD__.': Unsupported timezone given: Timzone: '.$this->timezone);
return false;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilTimeZone::switchTZ ( )

Switch timezone to given timezone.

public

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

References _switchTimeZone().

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

{
try
{
self::_switchTimeZone($this->timezone);
return true;
}
catch(ilTimeZoneException $exc)
{
// Shouldn't happen since this has been checked during initialisation
$this->log->write(__METHOD__.': Unsupported timezone given: Timzone: '.$this->timezone);
return false;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilTimeZone::validateTZ ( )

validate timezone

public

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

References restoreTZ(), and switchTZ().

{
// this is done by switching to the current tz
if($this->switchTZ() and $this->restoreTZ())
{
return true;
}
return false;
}

+ Here is the call graph for this function:

Field Documentation

ilTimeZone::$current_timezone = ''
staticprotected

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

ilTimeZone::$default_timezone = ''
staticprotected

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

Referenced by _getDefaultTimeZone().

ilTimeZone::$instances = array()
static

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

ilTimeZone::$log
protected

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

ilTimeZone::$server_timezone = ''
staticprotected

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

Referenced by _restoreDefaultTimeZone().

ilTimeZone::$timezone = "UTC"
protected

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

Referenced by getIdentifier().

ilTimeZone::$valid_tz = array()
static

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

Referenced by _getInstance().


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