Code Duplication    Length = 30-31 lines in 2 locations

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

@@ 1842-1871 (lines=30) @@
1839
		if ($componentType === 'VEVENT' && $component->DTSTART) {
1840
			$firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp();
1841
			// Finding the last occurrence is a bit harder
1842
			if (!isset($component->RRULE)) {
1843
				if (isset($component->DTEND)) {
1844
					$lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp();
1845
				} elseif (isset($component->DURATION)) {
1846
					$endDate = clone $component->DTSTART->getDateTime();
1847
					$endDate->add(DateTimeParser::parse($component->DURATION->getValue()));
1848
					$lastOccurrence = $endDate->getTimeStamp();
1849
				} elseif (!$component->DTSTART->hasTime()) {
1850
					$endDate = clone $component->DTSTART->getDateTime();
1851
					$endDate->modify('+1 day');
1852
					$lastOccurrence = $endDate->getTimeStamp();
1853
				} else {
1854
					$lastOccurrence = $firstOccurrence;
1855
				}
1856
			} else {
1857
				$it = new EventIterator($vObject, (string)$component->UID);
1858
				$maxDate = new \DateTime(self::MAX_DATE);
1859
				if ($it->isInfinite()) {
1860
					$lastOccurrence = $maxDate->getTimestamp();
1861
				} else {
1862
					$end = $it->getDtEnd();
1863
					while($it->valid() && $end < $maxDate) {
1864
						$end = $it->getDtEnd();
1865
						$it->next();
1866
1867
					}
1868
					$lastOccurrence = $end->getTimestamp();
1869
				}
1870
1871
			}
1872
		}
1873
1874
		if ($component->CLASS) {

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

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