19declare(strict_types=1);
34 public const UTC =
'UTC';
54 $this->log =
$DIC->logger()->cal();
57 $this->timezone = $a_timezone;
62 if (!self::$server_timezone) {
66 if (!self::$default_timezone) {
73 return array(
'timezone');
79 $this->log =
$DIC->logger()->cal();
97 $instance = self::$instances[$a_tz] ?? (self::$instances[$a_tz] =
new ilTimeZone($a_tz));
100 if (!array_key_exists($instance->getIdentifier(), self::$valid_tz)) {
101 if (!$instance->validateTZ()) {
104 self::$valid_tz[$instance->getIdentifier()] =
true;
121 $this->log->warning(
': Unsupported timezone given: Timzone: ' . $this->timezone);
136 $this->log->warning(
': Unsupported timezone given: Timzone: ' . $this->timezone);
154 $logger =
$DIC->logger()->cal();
155 if (self::$current_timezone == $a_timezone) {
160 if (function_exists(
'date_default_timezone_set')) {
161 if (!date_default_timezone_set($a_timezone)) {
162 $logger->info(
'Invalid timezone given. Timezone: ' . $a_timezone);
165 #$ilLog->write(__METHOD__.': Switched timezone to: '.$a_timezone);
166 self::$current_timezone = $a_timezone;
169 if (!putenv(
'TZ=' . $a_timezone)) {
170 $logger->warning(
'Cannot set TZ environment variable. Please register TZ in php.ini (safe_mode_allowed_env_vars). Timezone');
173 self::$current_timezone = $a_timezone;
180 if (!self::$server_timezone) {
183 self::$default_timezone = $a_tz;
197 if (strlen(self::$default_timezone)) {
202 if (function_exists(
'date_default_timezone_get') and $tz = date_default_timezone_get()) {
203 return self::$default_timezone = $tz;
206 if ($tz = ini_get(
'date.timezone')) {
207 return self::$default_timezone = $tz;
210 if ($tz = getenv(
'PHP_TZ')) {
211 return self::$default_timezone = $tz;
214 if ($tz = getenv(
'TZ')) {
215 return self::$default_timezone = $tz;
217 if (strlen($tz = date(
'T'))) {
218 return self::$default_timezone = $tz;
220 return self::$default_timezone =
self::UTC;
228 $tz =
$ini->readVariable(
'server',
'timezone');
235 date_default_timezone_set($tz);
INIFile Parser Early access in init proceess! Avoid further dependencies like logging or other servic...
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