• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/util/calendar.php
  • Класс: BitrixTasksUtilCalendar
  • Вызов: Calendar::processEachDay
protected function processEachDay(DateTime $startDate = null, DateTime $endDate = null, $isForward = false, $callback = false)
{
	if(!is_callable($callback))
	{
		return 0;
	}

	// you can not use DateTime::createFromTimestamp() here, because in this case, you`ll loose information about the timezone (was UTC, will be local zone)
	$currentDate = 	DateTime::createFromTimestampGmt($isForward ? $startDate->getTimestamp() : $endDate->getTimestamp());
	$endless = 		$isForward ? !$endDate : !$startDate;

	/*
	$intervals = $this->getWorkHours($currentDate);
	print_r('iv:'.PHP_EOL);
	print_r($intervals);
	*/
	/*
	$n = DateTime::createFromTimeStructGmt(array(
		'hours' => 10,
		'minutes' => 30,
		'seconds' => 0,
		'mon' => 9,
		'day' => 20,
		'year' => 2015
	), true);
	print_r('currentDate: '.$n->getInfoGmt().PHP_EOL);
	*/

	while ($endless || ($isForward ? ($currentDate->getTimestamp() < $endDate->getTimestamp()) : ($currentDate->getTimestamp() > $startDate->getTimestamp())))
	{
		//print_r('currentDate: '.$currentDate->getInfoGmt().PHP_EOL);

		$intervals = $this->getWorkHours($currentDate);
		// walk on $intervals from start to end or visa-versa
		for ($i = ($isForward ? 0 : count($intervals) - 1); ($isForward ? $i < count($intervals) : $i >= 0); ($isForward ? $i++ : $i--))
		{
			$interval = 		$intervals[$i];
			$intervalStart = 	$interval['startDate'];
			$intervalEnd = 		$interval['endDate'];

			//print_r('Interval:'.PHP_EOL);
			//print_r($intervalStart->getInfoGmt().' - '.$intervalEnd->getInfoGmt().PHP_EOL);

			if (($endDate !== null && $intervalStart->checkGT($endDate)) || ($startDate !== null && $intervalEnd->checkLT($startDate)))
			{
				continue;
			}

			$availableStart = 	($startDate !== null && $intervalStart->checkLT($startDate)) ? $startDate : $intervalStart;
			$availableEnd = 	($endDate !== null && $intervalEnd->checkGT($endDate)) ? $endDate : $intervalEnd;

			//print_r('once: '.$availableStart->getInfoGmt().' '.$availableEnd->getInfoGmt().PHP_EOL);
			if(call_user_func_array($callback, array($availableStart, $availableEnd)) === false)
			{
				return false;
			}
		}

		$currentDate->stripTime();
		$currentDate->addDay($isForward ? 1 : -1);
	}
}