@@ -47,16 +47,7 @@ public function calendar(): Collection
4747 $ occurrences = $ this
4848 ->generator ()
4949 ->between (from: $ from , to: $ to )
50- ->groupBy (function (Entry $ occurrence ) {
51- $ periodInTimezone = CarbonPeriodImmutable::between (
52- $ occurrence ->start ->setTimezone ($ this ->params ->get ('timezone ' ) ?? Generator::defaultTimezone ())->startOfDay (),
53- $ occurrence ->end ->setTimezone ($ this ->params ->get ('timezone ' ) ?? Generator::defaultTimezone ())->endOfDay ()
54- );
55-
56- return collect ($ periodInTimezone ->toArray ())
57- ->map (fn (CarbonImmutable $ date ) => $ date ->toDateString ())
58- ->all ();
59- })
50+ ->groupBy ($ this ->spanningDays ())
6051 ->map (fn (EntryCollection $ occurrences , string $ date ) => $ this ->day (date: $ date , occurrences: $ occurrences ));
6152
6253 $ days = $ this ->output ($ this ->makeEmptyDates (from: $ from , to: $ to )->merge ($ occurrences )->values ());
@@ -252,4 +243,16 @@ private function parseTermIds(string $key, array|Builder|string $terms): array
252243 ->map (fn (Term |string $ term ) => $ this ->getTermId (handle: $ handle , term: $ term ))
253244 ->all ();
254245 }
246+
247+ private function spanningDays (): \Closure
248+ {
249+ return function (Entry $ occurrence ) {
250+ $ spanningDays = CarbonPeriodImmutable::between (
251+ $ occurrence ->start ->startOfDay (),
252+ $ occurrence ->end ->endOfDay ()
253+ )->toArray ();
254+
255+ return collect ($ spanningDays )->map (fn (CarbonImmutable $ date ) => $ date ->toDateString ())->all ();
256+ };
257+ }
255258}
0 commit comments