Skip to content

Commit

Permalink
RRule: Register end time using Rule::setUntil() instead
Browse files Browse the repository at this point in the history
fixes #35
  • Loading branch information
nilmerg committed Mar 29, 2023
1 parent af643e1 commit b245755
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/RRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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;
}
Expand Down
17 changes: 17 additions & 0 deletions tests/RRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
);
}
}

0 comments on commit b245755

Please sign in to comment.