41 include_once(
'Services/Calendar/classes/class.ilTimeZoneException.php');
73 $this->timezone = $a_timezone;
77 $this->timezone = self::_getDefaultTimeZone();
80 if(!self::$server_timezone)
82 self::$server_timezone = self::_getDefaultTimeZone();
85 if(!self::$default_timezone)
87 self::_getDefaultTimeZone();
117 $a_tz = self::_getDefaultTimeZone();
120 if(isset(self::$instances[$a_tz]))
122 $instance = self::$instances[$a_tz];
126 $instance = self::$instances[$a_tz] =
new ilTimeZone($a_tz);
130 if(!array_key_exists($instance->getIdentifier(),self::$valid_tz))
132 if(!$instance->validateTZ())
136 self::$valid_tz[$instance->getIdentifier()] =
true;
152 self::_switchTimeZone($this->timezone);
158 $this->log->write(__METHOD__.
': Unsupported timezone given: Timzone: '.$this->timezone);
172 self::_switchTimeZone(self::$default_timezone);
178 $this->log->write(__METHOD__.
': Unsupported timezone given: Timzone: '.$this->timezone);
210 if(self::$current_timezone == $a_timezone)
212 #$ilLog->write(__METHOD__.': Do not switch to active timezone: '.$a_timezone); 217 if(function_exists(
'date_default_timezone_set'))
219 if(!date_default_timezone_set($a_timezone))
221 $ilLog->write(__METHOD__.
': Invalid timezone given. Timezone: '.$a_timezone);
224 #$ilLog->write(__METHOD__.': Switched timezone to: '.$a_timezone); 225 self::$current_timezone = $a_timezone;
228 if(!putenv(
'TZ='.$a_timezone))
230 $ilLog->write(__METHOD__.
': Cannot set TZ environment variable. Please register TZ in php.ini (safe_mode_allowed_env_vars). Timezone');
233 self::$current_timezone = $a_timezone;
248 if(!self::$server_timezone)
250 self::$server_timezone = self::_getDefaultTimeZone();
253 self::$default_timezone = $a_tz;
266 self::$default_timezone = self::$server_timezone;
267 self::_switchTimeZone(self::$default_timezone);
279 if(strlen(self::$default_timezone))
281 return self::$default_timezone;
284 if(function_exists(
'date_default_timezone_get') and $tz = date_default_timezone_get())
286 return self::$default_timezone = $tz;
289 if($tz = ini_get(
'date.timezone'))
291 return self::$default_timezone = $tz;
294 if($tz = getenv(
'PHP_TZ'))
296 return self::$default_timezone = $tz;
299 if($tz = getenv(
'TZ'))
301 return self::$default_timezone = $tz;
303 if(strlen($tz = date(
'T')))
305 return self::$default_timezone = $tz;
307 return self::$default_timezone = self::UTC;
static _getDefaultTimeZone()
Calculate and set default time zone.
validateTZ()
validate timezone
This class offers methods for timezone handling.
getIdentifier()
get identifier
switchTZ()
Switch timezone to given timezone.
__construct($a_timezone)
Create new timezone object If no timezone is given, the default server timezone is chosen...
static _setDefaultTimeZone($a_tz)
set default timezone
restoreTZ()
Restore default timezone.
static _restoreDefaultTimeZone()
restore default timezone to server timezone
Class for TimeZone exceptions.
static _getInstance($a_tz='')
get instance by timezone
static _switchTimeZone($a_timezone)
Switch tz.