Month::calculateAlternatingWithDays

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. Month
  4. calculateAlternatingWithDays
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/recurring/datetype/month.php
  • Класс: Bitrix\Crm\Recurring\DateType\Month
  • Вызов: Month::calculateAlternatingWithDays
private function calculateAlternatingWithDays()
{
	$this->setMonthBeginning();
	$resultDate = $this->startDate;
	if ($this->type === self::TYPE_DAY_OF_ALTERNATING_MONTHS)
	{
		$resultDate = clone($this->monthBeginning);
		if (!$this->isWorkdayType())
		{
			$day = $this->getDayNumber();
			if ($day === self::LAST_MONTH_DAY)
			{
				$resultDate->add("+ 1 month")->add("- 1 day");
			}
			elseif ($day > 1)
			{
				$day = $day - 1;
				$resultDate->add("{$day} days");
			}
			$timestamp = $resultDate->getTimestamp();
			if ($timestamp < $this->startDate->getTimestamp())
			{
				$resultDate->add('+ 1 month');
			}
		}
		else
		{
			$resultDate = Day::calculateForWorkingDays($this->params, $resultDate, $this->monthBeginning->format('t'));
			if ($this->startDate->getTimestamp() > $resultDate->getTimestamp())
			{
				$resultDate = $this->monthBeginning->add('+ 1 month');
				$resultDate = Day::calculateForWorkingDays($this->params, $resultDate, $this->monthBeginning->format('t'));
			}
		}
	}
	elseif ($this->type === self::TYPE_WEEKDAY_OF_ALTERNATING_MONTHS)
	{
		$resultDate = $this->calculateForWeekdayType($this->params, $this->monthBeginning);
		if ($this->startDate->getTimestamp() > $resultDate->getTimestamp())
		{
			$resultDate = $this->calculateForWeekdayType($this->params, $this->monthBeginning->add("+1 months"));
		}
	}

	return $resultDate;
}

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