public function findCalendar(Query $query, array $options) {
		$field = $this->getConfig('field');

		$year = $options[static::YEAR];
		$month = $options[static::MONTH];

		$from = new Time($year . '-' . $month . '-01');
		$lastDayOfMonth = $from->daysInMonth;

		$to = new Time($year . '-' . $month . '-' . $lastDayOfMonth . ' 23:59:59');

		$conditions = [
			$field . ' >=' => $from,
			$field . ' <=' => $to
		];
		if ($this->getConfig('endField')) {
			$endField = $this->getConfig('endField');

			$conditions = [
				'OR' => [
					[
						$field . ' <=' => $to,
						$endField . ' >' => $from,
					],
					$conditions
				]
			];
		}

		$query->where($conditions);
		if ($this->getConfig('scope')) {
			$query->andWhere($this->getConfig('scope'));
		}

		return $query;
	}
public function findCalendar(Query $query, array $options) {
		$field = $this->getConfig('field');

		$year = $options[static::YEAR];
		$month = $options[static::MONTH];

		$from = new Time($year . '-' . $month . '-01');
		$lastDayOfMonth = $from->daysInMonth;

		$to = new Time($year . '-' . $month . '-' . $lastDayOfMonth . ' 23:59:59');

		$conditions = [
			$field . ' >=' => $from,
			$field . ' <=' => $to
		];
		if ($this->getConfig('endField')) {
			$endField = $this->getConfig('endField');

			$conditions = [
				'OR' => [
					[
						$field . ' <=' => $to,
						$endField . ' >' => $from,
					],
					$conditions
				]
			];
		}

		$query->where($conditions);
		if ($this->getConfig('scope')) {
			$query->andWhere($this->getConfig('scope'));
		}

		return $query;
	}
public function findCalendar ( Query $ query , array $ options ) { $ field = $ this -> getConfig ( 'field' ) ; $ year = $ options [ static :: YEAR ] ; $ month = $ options [ static :: MONTH ] ; $ from = new Time ( $ year . '-' . $ month . '-01' ) ; $ lastDayOfMonth = $ from -> daysInMonth ; $ to = new Time ( $ year . '-' . $ month . '-' . $ lastDayOfMonth . ' 23:59:59' ) ; $ conditions = [ $ field . ' >=' => $ from , $ field . ' <=' => $ to ] ; if ( $ this -> getConfig ( 'endField' ) ) { $ endField = $ this -> getConfig ( 'endField' ) ; $ conditions = [ 'OR' => [ [ $ field . ' <=' => $ to , $ endField . ' >' => $ from , ] , $ conditions ] ] ; } $ query -> where ( $ conditions ) ; if ( $ this -> getConfig ( 'scope' ) ) { $ query -> andWhere ( $ this -> getConfig ( 'scope' ) ) ; } return $ query ; }
Custom finder for Calendars field.

Options:
- year (required), best to use CalendarBehavior::YEAR constant
- month (required), best to use CalendarBehavior::MONTH constant

@param \Cake\ORM\Query $query Query.
@param array $options Array of options as described above
@return \Cake\ORM\Query
Custom finder for Calendars field .