- Модуль: dav
- Путь к файлу: ~/bitrix/modules/dav/classes/general/icalendartimezone.php
- Класс: CDavICalendarTimeZone
- Вызов: CDavICalendarTimeZone::getTimeZoneId
static function getTimeZoneId($userId = null, $date = null)
{
global $USER;
$dateKey = $date ?? 0;
$userIdKey = $userId ?? 0;
if ($userId === null)
{
$userId = $USER->GetID();
}
static $timezoneCache = [];
if (isset($timezoneCache[$userIdKey][$dateKey]))
{
return $timezoneCache[$userIdKey][$dateKey];
}
$autoTimeZone = $userZone = '';
$factOffset = 0;
if ($date === null)
{
$date = time();
}
static $userCache = [];
if ($userId === null)
{
$autoTimeZone = trim($USER->GetParam("AUTO_TIME_ZONE"));
$userZone = $USER->GetParam("TIME_ZONE");
}
else
{
if (!isset($userCache[$userId]))
{
$dbUser = CUser::GetList(
"id",
"asc",
array("ID_EQUAL_EXACT" => (int)$userId),
array("FIELDS" => array("AUTO_TIME_ZONE", "TIME_ZONE", "TIME_ZONE_OFFSET"))
);
if (($arUser = $dbUser->Fetch()))
{
$userCache[$userId] = array(
"AUTO_TIME_ZONE" => trim($arUser["AUTO_TIME_ZONE"] ?? ''),
"TIME_ZONE" => $arUser["TIME_ZONE"],
"TIME_ZONE_OFFSET" => $arUser["TIME_ZONE_OFFSET"]
);
}
}
if (isset($userCache[$userId]))
{
$autoTimeZone = $userCache[$userId]["AUTO_TIME_ZONE"];
$userZone = $userCache[$userId]["TIME_ZONE"];
$factOffset = $userCache[$userId]["TIME_ZONE_OFFSET"];
}
}
if (CTimeZone::IsAutoTimeZone($autoTimeZone))
{
static $userOffsetCache = array();
if (!isset($userOffsetCache[$userId ?? 0]))
{
$userOffsetCache[$userIdKey] = CTimeZone::GetOffset($userId);
}
$userOffset = $userOffsetCache[$userIdKey];
$localTime = new DateTime();
$localOffset = $localTime->getOffset();
$timezoneCache[$userIdKey][$dateKey] = self::getTimezoneByOffset($date, $userOffset + $localOffset);
}
else
{
if ($userZone && isset(self::$arTimeZones[$userZone]))
{
$timezoneCache[$userIdKey][$dateKey] = $userZone;
}
else
{
$localTime = new DateTime();
$localOffset = $localTime->getOffset();
$timezoneCache[$userIdKey][$dateKey] = self::getTimezoneByOffset($date, $factOffset + $localOffset);
}
}
return $timezoneCache[$userIdKey][$dateKey];
}