Code Duplication    Length = 30-31 lines in 2 locations

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

@@ 158-188 (lines=31) @@
155
156
		$firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp();
157
		// Finding the last occurrence is a bit harder
158
		if (!isset($component->RRULE)) {
159
			if (isset($component->DTEND)) {
160
				$lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp();
161
			} elseif (isset($component->DURATION)) {
162
				$endDate = clone $component->DTSTART->getDateTime();
163
				// $component->DTEND->getDateTime() returns DateTimeImmutable
164
				$endDate = $endDate->add(DateTimeParser::parse($component->DURATION->getValue()));
165
				$lastOccurrence = $endDate->getTimeStamp();
166
			} elseif (!$component->DTSTART->hasTime()) {
167
				$endDate = clone $component->DTSTART->getDateTime();
168
				// $component->DTSTART->getDateTime() returns DateTimeImmutable
169
				$endDate = $endDate->modify('+1 day');
170
				$lastOccurrence = $endDate->getTimeStamp();
171
			} else {
172
				$lastOccurrence = $firstOccurrence;
173
			}
174
		} else {
175
			$it = new EventIterator($vObject, (string)$component->UID);
176
			$maxDate = new \DateTime(self::MAX_DATE);
177
			if ($it->isInfinite()) {
178
				$lastOccurrence = $maxDate->getTimestamp();
179
			} else {
180
				$end = $it->getDtEnd();
181
				while($it->valid() && $end < $maxDate) {
182
					$end = $it->getDtEnd();
183
					$it->next();
184
185
				}
186
				$lastOccurrence = $end->getTimestamp();
187
			}
188
		}
189
190
		$currentTime = $this->timeFactory->getTime();
191
		return $lastOccurrence < $currentTime;

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

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