Code Duplication    Length = 30-31 lines in 2 locations

apps/dav/lib/CalDAV/Schedule/IMipPlugin.php 1 location

@@ 261-291 (lines=31) @@
258
259
		$firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp();
260
		// Finding the last occurrence is a bit harder
261
		if (!isset($component->RRULE)) {
262
			if (isset($component->DTEND)) {
263
				$lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp();
264
			} elseif (isset($component->DURATION)) {
265
				/** @var \DateTime $endDate */
266
				$endDate = clone $component->DTSTART->getDateTime();
267
				// $component->DTEND->getDateTime() returns DateTimeImmutable
268
				$endDate = $endDate->add(DateTimeParser::parse($component->DURATION->getValue()));
269
				$lastOccurrence = $endDate->getTimestamp();
270
			} elseif (!$component->DTSTART->hasTime()) {
271
				/** @var \DateTime $endDate */
272
				$endDate = clone $component->DTSTART->getDateTime();
273
				// $component->DTSTART->getDateTime() returns DateTimeImmutable
274
				$endDate = $endDate->modify('+1 day');
275
				$lastOccurrence = $endDate->getTimestamp();
276
			} else {
277
				$lastOccurrence = $firstOccurrence;
278
			}
279
		} else {
280
			$it = new EventIterator($vObject, (string)$component->UID);
281
			$maxDate = new \DateTime(self::MAX_DATE);
282
			if ($it->isInfinite()) {
283
				$lastOccurrence = $maxDate->getTimestamp();
284
			} else {
285
				$end = $it->getDtEnd();
286
				while($it->valid() && $end < $maxDate) {
287
					$end = $it->getDtEnd();
288
					$it->next();
289
290
				}
291
				$lastOccurrence = $end->getTimestamp();
292
			}
293
		}
294

apps/dav/lib/CalDAV/CalDavBackend.php 1 location

@@ 2058-2087 (lines=30) @@
2055
		if ($componentType === 'VEVENT' && $component->DTSTART) {
2056
			$firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp();
2057
			// Finding the last occurrence is a bit harder
2058
			if (!isset($component->RRULE)) {
2059
				if (isset($component->DTEND)) {
2060
					$lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp();
2061
				} elseif (isset($component->DURATION)) {
2062
					$endDate = clone $component->DTSTART->getDateTime();
2063
					$endDate->add(DateTimeParser::parse($component->DURATION->getValue()));
2064
					$lastOccurrence = $endDate->getTimeStamp();
2065
				} elseif (!$component->DTSTART->hasTime()) {
2066
					$endDate = clone $component->DTSTART->getDateTime();
2067
					$endDate->modify('+1 day');
2068
					$lastOccurrence = $endDate->getTimeStamp();
2069
				} else {
2070
					$lastOccurrence = $firstOccurrence;
2071
				}
2072
			} else {
2073
				$it = new EventIterator($vObject, (string)$component->UID);
2074
				$maxDate = new \DateTime(self::MAX_DATE);
2075
				if ($it->isInfinite()) {
2076
					$lastOccurrence = $maxDate->getTimestamp();
2077
				} else {
2078
					$end = $it->getDtEnd();
2079
					while($it->valid() && $end < $maxDate) {
2080
						$end = $it->getDtEnd();
2081
						$it->next();
2082
2083
					}
2084
					$lastOccurrence = $end->getTimestamp();
2085
				}
2086
2087
			}
2088
		}
2089
2090
		if ($component->CLASS) {