WorkTime::convertToJS

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. WorkTime
  4. convertToJS
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/sitebutton/worktime.php
  • Класс: Bitrix\Crm\SiteButton\WorkTime
  • Вызов: WorkTime::convertToJS
static function convertToJS($workTime = array())
{
	static $timeZoneOffset = null;
	if ($timeZoneOffset === null)
	{
		$date = new \DateTime();
		if (!empty($workTime['TIME_ZONE']))
		{
			$dateTimeZone = new \DateTimeZone($workTime['TIME_ZONE']);
		}
		else
		{
			$dateTimeZone = $date->getTimezone();
		}
		$timeZoneOffset = $dateTimeZone->getOffset($date);
	}

	$holidays = count($workTime['HOLIDAYS']) > 0 ? $workTime['HOLIDAYS'] : null;
	$dayOffCodes = count($workTime['DAY_OFF']) > 0 ? $workTime['DAY_OFF'] : null;
	if ($dayOffCodes)
	{
		$days = array('SU' => 0, 'MO' => 1, 'TU' => 2, 'WE' => 3, 'TH' => 4, 'FR' => 5, 'SA' => 6);
		$dayOff = array();
		foreach ($dayOffCodes as $dayOffCode)
		{
			$dayOff[] = $days[$dayOffCode];
		}
	}
	else
	{
		$dayOff = null;
	}

	return array(
		'timeZoneOffset' => $timeZoneOffset / 60,
		'timeFrom' => (float) $workTime['TIME_FROM'],
		'timeTo' => (float) $workTime['TIME_TO'],
		'holidays' => $holidays,
		'dayOff' => $dayOff,
		'actionRule' => $workTime['ACTION_RULE'],
		'actionText' => $workTime['ACTION_TEXT'],
	);
}

Добавить комментарий