Sabre\VObject\Recur\EventIterator::getDtEnd PHP Method

getDtEnd() public method

This method returns the end date for the current iteration of the event.
public getDtEnd ( ) : DateTime
return DateTime
    public function getDtEnd()
    {
        if (!$this->valid()) {
            return null;
        }
        $end = clone $this->currentDate;
        $end->modify('+' . $this->eventDuration . ' seconds');
        return $end;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Parses some information from calendar objects, used for optimized
  * calendar-queries.
  *
  * Returns an array with the following keys:
  *   * etag - An md5 checksum of the object without the quotes.
  *   * size - Size of the object in bytes
  *   * componentType - VEVENT, VTODO or VJOURNAL
  *   * firstOccurence
  *   * lastOccurence
  *   * uid - value of the UID property
  *
  * @param string $calendarData
  * @return array
  */
 public function getDenormalizedData($calendarData)
 {
     $vObject = Reader::read($calendarData);
     $componentType = null;
     $component = null;
     $firstOccurrence = null;
     $lastOccurrence = null;
     $uid = null;
     $classification = self::CLASSIFICATION_PUBLIC;
     foreach ($vObject->getComponents() as $component) {
         if ($component->name !== 'VTIMEZONE') {
             $componentType = $component->name;
             $uid = (string) $component->UID;
             break;
         }
     }
     if (!$componentType) {
         throw new \Sabre\DAV\Exception\BadRequest('Calendar objects must have a VJOURNAL, VEVENT or VTODO component');
     }
     if ($componentType === 'VEVENT' && $component->DTSTART) {
         $firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp();
         // Finding the last occurrence is a bit harder
         if (!isset($component->RRULE)) {
             if (isset($component->DTEND)) {
                 $lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp();
             } elseif (isset($component->DURATION)) {
                 $endDate = clone $component->DTSTART->getDateTime();
                 $endDate->add(DateTimeParser::parse($component->DURATION->getValue()));
                 $lastOccurrence = $endDate->getTimeStamp();
             } elseif (!$component->DTSTART->hasTime()) {
                 $endDate = clone $component->DTSTART->getDateTime();
                 $endDate->modify('+1 day');
                 $lastOccurrence = $endDate->getTimeStamp();
             } else {
                 $lastOccurrence = $firstOccurrence;
             }
         } else {
             $it = new EventIterator($vObject, (string) $component->UID);
             $maxDate = new \DateTime(self::MAX_DATE);
             if ($it->isInfinite()) {
                 $lastOccurrence = $maxDate->getTimeStamp();
             } else {
                 $end = $it->getDtEnd();
                 while ($it->valid() && $end < $maxDate) {
                     $end = $it->getDtEnd();
                     $it->next();
                 }
                 $lastOccurrence = $end->getTimeStamp();
             }
         }
     }
     if ($component->CLASS) {
         $classification = CalDavBackend::CLASSIFICATION_PRIVATE;
         switch ($component->CLASS->getValue()) {
             case 'PUBLIC':
                 $classification = CalDavBackend::CLASSIFICATION_PUBLIC;
                 break;
             case 'CONFIDENTIAL':
                 $classification = CalDavBackend::CLASSIFICATION_CONFIDENTIAL;
                 break;
         }
     }
     return ['etag' => md5($calendarData), 'size' => strlen($calendarData), 'componentType' => $componentType, 'firstOccurence' => is_null($firstOccurrence) ? null : max(0, $firstOccurrence), 'lastOccurence' => $lastOccurrence, 'uid' => $uid, 'classification' => $classification];
 }
All Usage Examples Of Sabre\VObject\Recur\EventIterator::getDtEnd