41include_once(
'Services/Calendar/classes/class.ilTimeZoneException.php');
69 $this->log =
$DIC->logger()->cal();
72 $this->timezone = $a_timezone;
77 if (!self::$server_timezone) {
81 if (!self::$default_timezone) {
88 return array(
'timezone');
95 $this->log =
$DIC->logger()->cal();
126 if (isset(self::$instances[$a_tz])) {
127 $instance = self::$instances[$a_tz];
129 $instance = self::$instances[$a_tz] =
new ilTimeZone($a_tz);
133 if (!array_key_exists($instance->getIdentifier(), self::$valid_tz)) {
134 if (!$instance->validateTZ()) {
137 self::$valid_tz[$instance->getIdentifier()] =
true;
156 $this->log->write(__METHOD__ .
': Unsupported timezone given: Timzone: ' . $this->timezone);
173 $this->log->write(__METHOD__ .
': Unsupported timezone given: Timzone: ' . $this->timezone);
204 $logger =
$DIC->logger()->cal();
206 if (self::$current_timezone == $a_timezone) {
211 if (function_exists(
'date_default_timezone_set')) {
212 if (!date_default_timezone_set($a_timezone)) {
213 $logger->info(
'Invalid timezone given. Timezone: ' . $a_timezone);
216 #$ilLog->write(__METHOD__.': Switched timezone to: '.$a_timezone);
217 self::$current_timezone = $a_timezone;
220 if (!putenv(
'TZ=' . $a_timezone)) {
221 $logger->warning(
'Cannot set TZ environment variable. Please register TZ in php.ini (safe_mode_allowed_env_vars). Timezone');
224 self::$current_timezone = $a_timezone;
239 if (!self::$server_timezone) {
243 self::$default_timezone = $a_tz;
269 if (strlen(self::$default_timezone)) {
274 if (function_exists(
'date_default_timezone_get') and
$tz = @date_default_timezone_get()) {
275 return self::$default_timezone =
$tz;
278 if (
$tz = ini_get(
'date.timezone')) {
279 return self::$default_timezone =
$tz;
282 if (
$tz = getenv(
'PHP_TZ')) {
283 return self::$default_timezone =
$tz;
286 if (
$tz = getenv(
'TZ')) {
287 return self::$default_timezone =
$tz;
289 if (strlen(
$tz = date(
'T'))) {
290 return self::$default_timezone =
$tz;
292 return self::$default_timezone =
self::UTC;
301 $tz =
$ini->readVariable(
'server',
'timezone');
308 date_default_timezone_set(
$tz);
An exception for terminatinating execution or to throw for unit testing.
Class for TimeZone exceptions.
This class offers methods for timezone handling.
restoreTZ()
Restore default timezone.
static initDefaultTimeZone(ilIniFile $ini)
Initialize default timezone from system settings.
getIdentifier()
get identifier
static _restoreDefaultTimeZone()
restore default timezone to server timezone
static _getDefaultTimeZone()
Calculate and set default time zone.
static _switchTimeZone($a_timezone)
Switch tz.
static _setDefaultTimeZone($a_tz)
set default timezone
static _getInstance($a_tz='')
get instance by timezone
__construct($a_timezone)
Create new timezone object If no timezone is given, the default server timezone is chosen.
switchTZ()
Switch timezone to given timezone.
validateTZ()
validate timezone