Code Duplication    Length = 30-31 lines in 2 locations

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

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

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

@@ 1860-1889 (lines=30) @@
1857
		if ($componentType === 'VEVENT' && $component->DTSTART) {
1858
			$firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp();
1859
			// Finding the last occurrence is a bit harder
1860
			if (!isset($component->RRULE)) {
1861
				if (isset($component->DTEND)) {
1862
					$lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp();
1863
				} elseif (isset($component->DURATION)) {
1864
					$endDate = clone $component->DTSTART->getDateTime();
1865
					$endDate->add(DateTimeParser::parse($component->DURATION->getValue()));
1866
					$lastOccurrence = $endDate->getTimeStamp();
1867
				} elseif (!$component->DTSTART->hasTime()) {
1868
					$endDate = clone $component->DTSTART->getDateTime();
1869
					$endDate->modify('+1 day');
1870
					$lastOccurrence = $endDate->getTimeStamp();
1871
				} else {
1872
					$lastOccurrence = $firstOccurrence;
1873
				}
1874
			} else {
1875
				$it = new EventIterator($vObject, (string)$component->UID);
1876
				$maxDate = new \DateTime(self::MAX_DATE);
1877
				if ($it->isInfinite()) {
1878
					$lastOccurrence = $maxDate->getTimestamp();
1879
				} else {
1880
					$end = $it->getDtEnd();
1881
					while($it->valid() && $end < $maxDate) {
1882
						$end = $it->getDtEnd();
1883
						$it->next();
1884
1885
					}
1886
					$lastOccurrence = $end->getTimestamp();
1887
				}
1888
1889
			}
1890
		}
1891
1892
		if ($component->CLASS) {