Skip to content

Commit

Permalink
Fix end timezone on recurring events that don't have an end_time
Browse files Browse the repository at this point in the history
…set (#82)
  • Loading branch information
edalzell authored Feb 14, 2024
1 parent dd6fdce commit 425703d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Types/RecurringEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function rule(): RRuleInterface
];

if ($end = $this->end_date) {
$rule['until'] = Carbon::parse($end)->endOfDay();
$rule['until'] = Carbon::parse($end)->shiftTimezone($this->timezone['timezone'])->endOfDay();
}

return new RRule($rule);
Expand Down
21 changes: 21 additions & 0 deletions tests/Unit/RecurringEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,25 @@ public function canCreateRecurringEvent()
// $this->assertNull($event->endDate());
// $this->assertNull($event->end());
// }

/** @test */
public function canShowLastOccurrenceWhenNoEndTime()
{
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));

$recurringEntry = tap(Entry::make()
->collection('events')
->data([
'start_date' => Carbon::now()->addDays(1)->toDateString(),
'start_time' => '22:00',
'recurrence' => 'daily',
'end_date' => Carbon::now()->addDays(2)->toDateString(),
'timezone' => 'America/Chicago',
]))->save();

$occurrences = Events::fromCollection(handle: 'events')
->between(Carbon::now(), Carbon::now()->addDays(5)->endOfDay());

$this->assertCount(2, $occurrences);
}
}

0 comments on commit 425703d

Please sign in to comment.