• Модуль: dav
  • Путь к файлу: ~/bitrix/modules/dav/classes/general/icalendartimezone.php
  • Класс: CDavICalendarTimeZone
  • Вызов: CDavICalendarTimeZone::getTimezoneByOffset
static function getTimezoneByOffset($date, $offset)
{
	foreach (self::$arTimeZones as $timeZoneCode => $timeZoneText)
	{
		$t = new CDavICalendarComponent();
		$t->InitializeFromString($timeZoneText);
		if ($t)
		{
			$arTimeMap = array();

			$comps = $t->GetComponents();
			foreach ($comps as $comp)
			{
				$t = self::ParseVTimezone($comp, intval(date("Y", (int)$date)));
				if ($t !== false)
				{
					$arTimeMap[] = $t;
				}
			}

			if ($arTimeMap)
			{
				usort($arTimeMap, function($a, $b) {return ($a['time'] > $b['time']) ? 1 : (($a['time'] < $b['time']) ? -1 : 0);});

				if ($date < $arTimeMap[0]['time'] && $arTimeMap[0]['from'] == $offset)
				{
					return $timeZoneCode;
				}

				for ($i = 0, $n = count($arTimeMap); $i < $n - 1; $i++)
				{
					if (($date >= $arTimeMap[$i]['time']) && ($date < $arTimeMap[$i + 1]['time']) && $arTimeMap[$i]['to'] == $offset)
					{
						return $timeZoneCode;
					}
				}

				if ($date >= $arTimeMap[$n - 1]['time'] && $arTimeMap[$n - 1]['to'] == $offset)
				{
					return $timeZoneCode;
				}
			}
		}
	}

	return false;
}