• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/kanban/timeline.php
  • Класс: BitrixTasksKanbanTimeLineTable
  • Вызов: TimeLineTable::getClosestWorkHour
static function getClosestWorkHour($timeStamp)
{
	// compatibility
	if ($timeStamp instanceof DateTime)
	{
		$timeStamp = $timeStamp->getTimestamp();
	}
	if (!is_int($timeStamp))
	{
		return false;
	}

	$calendar = new Calendar();
	$now = BitrixTasksUtilTypeDateTime::createFromTimestamp(time());
	$dateTime = BitrixTasksUtilTypeDateTime::createFromTimestamp($timeStamp);

	// get in the past, first work day
	while ($dateTime->checkGT($now))
	{
		if ($calendar->isWeekend($dateTime) || $calendar->isHoliday($dateTime))
		{
			$dateTime->addDay(-1);
		}
		else
		{
			break;
		}
	}

	$calendarSettings = Calendar::getSettings();
	if (isset($calendarSettings['HOURS']['END']['H'], $calendarSettings['HOURS']['END']['M']))
	{
		$dateTime->setTime($calendarSettings['HOURS']['END']['H'], $calendarSettings['HOURS']['END']['M']);
	}

	$result = date(self::getDatePhpFormat(), $dateTime->getTimestamp());
	while (
		$dateTime->checkLT($now)
		|| !$calendar->isWorkTime(BitrixTasksUtilTypeDateTime::createFromUserTimeGmt($result))
	)
	{
		$dateTime->addDay(1);
		$result = date(self::getDatePhpFormat(), $dateTime->getTimestamp());
	}

	return $result;
}