Skip to content

Commit 508c957

Browse files
committed
use period to match all spanning days
1 parent 53460fc commit 508c957

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/Tags/Events.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Carbon\CarbonImmutable;
77
use Carbon\CarbonInterface;
88
use Carbon\CarbonPeriod;
9+
use Carbon\CarbonPeriodImmutable;
910
use Illuminate\Pagination\Paginator;
1011
use Illuminate\Support\Collection;
1112
use Statamic\Contracts\Query\Builder;
@@ -47,10 +48,14 @@ public function calendar(): Collection
4748
->generator()
4849
->between(from: $from, to: $to)
4950
->groupBy(function (Entry $occurrence) {
50-
$start = $occurrence->start->setTimezone($this->params->get('timezone') ?? Generator::timezone());
51-
$end = $occurrence->end->setTimezone($this->params->get('timezone') ?? Generator::timezone());
52-
53-
return $start->isSameDay($end) ? $start->toDateString() : [$start->toDateString(), $end->toDateString()];
51+
$periodInTimezone = CarbonPeriodImmutable::between(
52+
$occurrence->start->setTimezone($this->params->get('timezone') ?? Generator::timezone())->startOfDay(),
53+
$occurrence->end->setTimezone($this->params->get('timezone') ?? Generator::timezone())->endOfDay()
54+
);
55+
56+
return collect($periodInTimezone->toArray())
57+
->map(fn (CarbonImmutable $date) => $date->toDateString())
58+
->all();
5459
})
5560
->map(fn(EntryCollection $occurrences, string $date) => $this->day(date: $date, occurrences: $occurrences));
5661

0 commit comments

Comments
 (0)