/**
  * Returns true if the period include the other period
  * given as argument
  *
  * @param PeriodInterface $period
  * @param bool            $strict
  *
  * @return bool
  */
 public function includes(PeriodInterface $period, $strict = true)
 {
     if (true === $strict) {
         return $this->getBegin() <= $period->getBegin() && $this->getEnd() >= $period->getEnd();
     }
     return $this->includes($period, true) || $period->includes($this, true) || $this->contains($period->getBegin()) || $this->contains($period->getEnd());
 }
Exemple #2
0
 /**
  * find events that matches the given period (during or over)
  *
  * @param \CalendR\Period\PeriodInterface $period
  * @param array                           $options
  *
  * @return array|EventInterface
  *
  * @throws NoProviderFound
  */
 public function find(PeriodInterface $period, array $options = array())
 {
     if (0 === count($this->providers)) {
         throw new NoProviderFound();
     }
     // Check if there's a provider option provided, used to filter the used providers
     $providers = isset($options['providers']) ? $options['providers'] : array();
     if (!is_array($providers)) {
         $providers = array($providers);
     }
     // Instantiate an event collection
     $collection = call_user_func($this->collectionInstantiator);
     foreach ($this->providers as $name => $provider) {
         if (count($providers) > 0 && !in_array($name, $providers)) {
             continue;
         }
         // Add matching events to the collection
         foreach ($provider->getEvents($period->getBegin(), $period->getEnd(), $options) as $event) {
             if ($period->containsEvent($event)) {
                 $collection->add($event);
             }
         }
     }
     return $collection;
 }
Exemple #3
0
 /**
  * Check if the event is during the given period
  *
  * @param \CalendR\Period\PeriodInterface $period
  * @return bool true if the event is during $period, false otherwise
  */
 function isDuring(PeriodInterface $period)
 {
     return $this->getBegin()->diff($period->getBegin())->invert == 1 && $this->getEnd()->diff($period->getEnd())->invert == 0;
 }
Exemple #4
0
 /**
  * {@inheritdoc}
  */
 public function key()
 {
     return (int) $this->current->getBegin()->format('G');
 }
 /**
  * Check if the event is during the given period
  *
  * @param  \CalendR\Period\PeriodInterface $period
  * @return bool                            true if the event is during $period, false otherwise
  */
 public function isDuring(PeriodInterface $period)
 {
     return $this->getBegin() >= $period->getBegin() && $this->getEnd() < $period->getEnd();
 }