3declare(strict_types=1);
40 public const UTC =
'UTC';
60 $this->log =
$DIC->logger()->cal();
63 $this->timezone = $a_timezone;
68 if (!self::$server_timezone) {
72 if (!self::$default_timezone) {
79 return array(
'timezone');
85 $this->log =
$DIC->logger()->cal();
103 $instance = self::$instances[$a_tz] ?? (self::$instances[$a_tz] =
new ilTimeZone($a_tz));
106 if (!array_key_exists($instance->getIdentifier(), self::$valid_tz)) {
107 if (!$instance->validateTZ()) {
110 self::$valid_tz[$instance->getIdentifier()] =
true;
127 $this->log->warning(
': Unsupported timezone given: Timzone: ' . $this->timezone);
142 $this->log->warning(
': Unsupported timezone given: Timzone: ' . $this->timezone);
160 $logger =
$DIC->logger()->cal();
161 if (self::$current_timezone == $a_timezone) {
166 if (function_exists(
'date_default_timezone_set')) {
167 if (!date_default_timezone_set($a_timezone)) {
168 $logger->info(
'Invalid timezone given. Timezone: ' . $a_timezone);
171 #$ilLog->write(__METHOD__.': Switched timezone to: '.$a_timezone);
172 self::$current_timezone = $a_timezone;
175 if (!putenv(
'TZ=' . $a_timezone)) {
176 $logger->warning(
'Cannot set TZ environment variable. Please register TZ in php.ini (safe_mode_allowed_env_vars). Timezone');
179 self::$current_timezone = $a_timezone;
186 if (!self::$server_timezone) {
189 self::$default_timezone = $a_tz;
203 if (strlen(self::$default_timezone)) {
208 if (function_exists(
'date_default_timezone_get') and $tz = date_default_timezone_get()) {
209 return self::$default_timezone = $tz;
212 if ($tz = ini_get(
'date.timezone')) {
213 return self::$default_timezone = $tz;
216 if ($tz = getenv(
'PHP_TZ')) {
217 return self::$default_timezone = $tz;
220 if ($tz = getenv(
'TZ')) {
221 return self::$default_timezone = $tz;
223 if (strlen($tz = date(
'T'))) {
224 return self::$default_timezone = $tz;
226 return self::$default_timezone =
self::UTC;
234 $tz =
$ini->readVariable(
'server',
'timezone');
241 date_default_timezone_set($tz);
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Component logger with individual log levels by component id.
Class for TimeZone exceptions.
This class offers methods for timezone handling.
static string $default_timezone
restoreTZ()
Restore default timezone.
static initDefaultTimeZone(ilIniFile $ini)
Initialize default timezone from system settings.
static _restoreDefaultTimeZone()
static _getDefaultTimeZone()
Calculate and set default time zone.
static string $current_timezone
static _setDefaultTimeZone(string $a_tz)
__construct(string $a_timezone)
Create new timezone object If no timezone is given, the default server timezone is chosen.
static _switchTimeZone(string $a_timezone)
switchTZ()
Switch timezone to given timezone.
static _getInstance(string $a_tz='')
get instance by timezone
static string $server_timezone