diff --git a/src/RRule.php b/src/RRule.php index 1723bfa..c5ef8bc 100644 --- a/src/RRule.php +++ b/src/RRule.php @@ -194,7 +194,7 @@ public function getStart(): ?DateTimeInterface } /** - * Set the end time of this frequency + * Set the time until this frequency lasts * * The given datetime will be cloned and microseconds removed since iCalendar datetimes only work to the second. * @@ -207,7 +207,7 @@ public function endAt(DateTimeInterface $end): self $end = clone $end; $end->setTime($end->format('H'), $end->format('i'), $end->format('s')); - $this->rrule->setEndDate($end); + $this->rrule->setUntil($end); return $this; } diff --git a/tests/RRuleTest.php b/tests/RRuleTest.php index beeeebd..ad76d88 100644 --- a/tests/RRuleTest.php +++ b/tests/RRuleTest.php @@ -3,6 +3,7 @@ namespace ipl\Tests\Scheduler; use DateTime; +use DateTimeZone; use ipl\Scheduler\Contract\Frequency; use ipl\Scheduler\RRule; use PHPUnit\Framework\TestCase; @@ -156,4 +157,20 @@ public function testJsonSerializeAndDeserialize() $this->assertEquals($rrule, RRule::fromJson(json_encode($rrule))); } + + public function testRecurrenceEndIsProperlySet() + { + $rrule = RRule::fromFrequency(RRule::DAILY) + ->startAt(new DateTime('2023-01-01T12:00:00', new DateTimeZone('UTC'))) + ->endAt(new DateTime('2024-01-01T12:00:00', new DateTimeZone('UTC'))); + + $this->assertSame( + [ + 'start' => '2023-01-01T12:00:00+00:00', + 'rrule' => 'FREQ=DAILY;UNTIL=20240101T120000Z', + 'frequency' => RRule::DAILY + ], + $rrule->jsonSerialize() + ); + } }