diff --git a/Classes/Service/DestinationDataImportService/DatesFactory.php b/Classes/Service/DestinationDataImportService/DatesFactory.php index 34672bf..e0aeda3 100644 --- a/Classes/Service/DestinationDataImportService/DatesFactory.php +++ b/Classes/Service/DestinationDataImportService/DatesFactory.php @@ -131,6 +131,9 @@ final class DatesFactory if (empty($date['repeatUntil']) === false) { return $date; } + if (empty($date['repeatCount']) === false) { + return $date; + } $date['repeatUntil'] = $this->getToday()->modify($import->getRepeatUntil())->format('c'); $this->logger->info('Interval did not provide repeatUntil.', ['newRepeat' => $date['repeatUntil']]); @@ -149,7 +152,7 @@ final class DatesFactory $timeZone = new DateTimeZone($date['tz']); $start = new DateTimeImmutable($date['start'], $timeZone); $end = new DateTimeImmutable($date['end'], $timeZone); - $until = new DateTimeImmutable($date['repeatUntil'], $timeZone); + $until = $this->createUntil($start, $date, 'days'); $period = new DatePeriod($start, new DateInterval('P1D'), $until); foreach ($period as $day) { @@ -179,7 +182,7 @@ final class DatesFactory $timeZone = new DateTimeZone($date['tz']); $start = new DateTimeImmutable($date['start'], $timeZone); $end = new DateTimeImmutable($date['end'], $timeZone); - $until = new DateTimeImmutable($date['repeatUntil'], $timeZone); + $until = $this->createUntil($start, $date, 'weeks'); foreach ($date['weekdays'] as $day) { $dateToUse = $start->modify($day); @@ -216,6 +219,21 @@ final class DatesFactory ); } + /** + * @param string $repeatCountUnit E.g. weeks or days + */ + private function createUntil( + DateTimeImmutable $start, + array $date, + string $repeatCountUnit, + ): DateTimeImmutable { + if (array_key_exists('repeatUntil', $date)) { + return new DateTimeImmutable($date['repeatUntil'], $start->getTimezone()); + } + + return $start->modify('+' . ((int)$date['repeatCount']) . ' ' . $repeatCountUnit); + } + private function getToday(): DateTimeImmutable { $today = $this->context->getPropertyFromAspect('date', 'full', new DateTimeImmutable()); diff --git a/Documentation/Changelog/5.0.1.rst b/Documentation/Changelog/5.1.0.rst similarity index 78% rename from Documentation/Changelog/5.0.1.rst rename to Documentation/Changelog/5.1.0.rst index 09069f5..8d17ce8 100644 --- a/Documentation/Changelog/5.0.1.rst +++ b/Documentation/Changelog/5.1.0.rst @@ -9,7 +9,10 @@ Nothing Features -------- -Nothing +* Support destination.one `repeatCount` property. + + This provides info on how often a repeatable event should be repeated. + E.g. `1` = exactly once, so no actual repeat. Fixes ----- diff --git a/Tests/Unit/Service/DestinationDataImportService/DatesFactoryTest.php b/Tests/Unit/Service/DestinationDataImportService/DatesFactoryTest.php index e2ac7e2..cca56fa 100644 --- a/Tests/Unit/Service/DestinationDataImportService/DatesFactoryTest.php +++ b/Tests/Unit/Service/DestinationDataImportService/DatesFactoryTest.php @@ -95,7 +95,7 @@ class DatesFactoryTest extends TestCase } #[Test] - public function returnsWeeklyWithConfiguredRepeat(): void + public function returnsWeeklyWithConfiguredRepeatEndless(): void { $import = self::createStub(Import::class); $import->method('getRepeatUntil')->willReturn('+60 days'); @@ -119,6 +119,78 @@ class DatesFactoryTest extends TestCase self::assertCount(16, $result); } + #[Test] + public function returnsWeeklyWithConfiguredRepeatCountOfOne(): void + { + $import = self::createStub(Import::class); + $import->method('getRepeatUntil')->willReturn('+60 days'); + $subject = $this->createTestSubject('2023-01-01T13:17:24 Europe/Berlin'); + + $result = $subject->createDates($import, [[ + 'weekdays' => [ + 'Monday', + ], + 'start' => '2023-01-06T14:00:00+01:00', + 'end' => '2023-01-06T15:00:00+01:00', + 'tz' => 'Europe/Berlin', + 'freq' => 'Weekly', + 'interval' => 1, + 'repeatCount' => 1, + ]], false); + + self::assertInstanceOf(Generator::class, $result); + $result = iterator_to_array($result); + + self::assertCount(1, $result); + } + + #[Test] + public function returnsWeeklyWithConfiguredRepeatCountOfThree(): void + { + $import = self::createStub(Import::class); + $import->method('getRepeatUntil')->willReturn('+60 days'); + $subject = $this->createTestSubject('2023-01-01T13:17:24 Europe/Berlin'); + + $result = $subject->createDates($import, [[ + 'weekdays' => [ + 'Monday', + ], + 'start' => '2023-01-06T14:00:00+01:00', + 'end' => '2023-01-06T15:00:00+01:00', + 'tz' => 'Europe/Berlin', + 'freq' => 'Weekly', + 'interval' => 1, + 'repeatCount' => 3, + ]], false); + + self::assertInstanceOf(Generator::class, $result); + $result = iterator_to_array($result); + + self::assertCount(3, $result); + } + + #[Test] + public function returnsDailyWithConfiguredRepeatCount(): void + { + $import = self::createStub(Import::class); + $import->method('getRepeatUntil')->willReturn('+60 days'); + $subject = $this->createTestSubject('2023-01-01T13:17:24 Europe/Berlin'); + + $result = $subject->createDates($import, [[ + 'start' => '2023-01-06T14:00:00+01:00', + 'end' => '2023-01-06T15:00:00+01:00', + 'tz' => 'Europe/Berlin', + 'freq' => 'Daily', + 'interval' => 1, + 'repeatCount' => 1, + ]], false); + + self::assertInstanceOf(Generator::class, $result); + $result = iterator_to_array($result); + + self::assertCount(1, $result); + } + #[Test] public function returnsSingleCanceledDate(): void { diff --git a/ext_emconf.php b/ext_emconf.php index 7f0e82b..c6257a4 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -9,7 +9,7 @@ $EM_CONF['events'] = [ 'author' => 'Dirk Koritnik, Daniel Siepmann', 'author_email' => 'koritnik@werkraum-media.de, coding@daniel-siepmann.de', 'state' => 'stable', - 'version' => '5.0.1', + 'version' => '5.1.0', 'constraints' => [ 'depends' => [ 'typo3' => '',