@@ -42,14 +42,14 @@ public function calendar(): Collection
4242 $ month = $ this ->params ->get ('month ' , now ()->englishMonth );
4343 $ year = $ this ->params ->get ('year ' , now ()->year );
4444
45- $ from = parse_date ($ month . ' ' . $ year )->startOfMonth ()->startOfWeek ();
46- $ to = parse_date ($ month . ' ' . $ year )->endOfMonth ()->endOfWeek ();
45+ $ from = parse_date ($ month. ' ' . $ year )->startOfMonth ()->startOfWeek ();
46+ $ to = parse_date ($ month. ' ' . $ year )->endOfMonth ()->endOfWeek ();
4747
4848 $ occurrences = $ this
4949 ->generator ()
5050 ->between (from: $ from , to: $ to )
5151 ->groupBy ($ this ->spanningDays ())
52- ->map (fn (EntryCollection $ occurrences , string $ date ) => $ this ->day (date: $ date , occurrences: $ occurrences ));
52+ ->map (fn (EntryCollection $ occurrences , string $ date ) => $ this ->day (date: $ date , occurrences: $ occurrences ));
5353
5454 $ days = $ this ->output ($ this ->makeEmptyDates (from: $ from , to: $ to )->merge ($ occurrences )->values ());
5555
@@ -136,22 +136,27 @@ public function upcoming(): EntryCollection|array
136136 return $ this ->output ($ occurrences ->take ($ limit ));
137137 }
138138
139+ private function addSpanningStartEnd (string $ date , EntryCollection $ occurrences ): EntryCollection
140+ {
141+ return $ occurrences ->map (function (Entry $ occurrence ) use ($ date ) {
142+ if (! $ occurrence ->spanning ) {
143+ return $ occurrence ;
144+ }
145+
146+ $ carbonDate = Carbon::parse ($ date )->shiftTimezone ($ occurrence ->start ->timezone );
147+ $ occurrence
148+ ->setSupplement ('spanning_start ' , $ occurrence ->start ->isSameDay ($ carbonDate ))
149+ ->setSupplement ('spanning_end ' , $ occurrence ->end ->isSameDay ($ carbonDate ));
150+
151+ return clone $ occurrence ;
152+ });
153+ }
154+
139155 private function day (string $ date , EntryCollection $ occurrences ): array
140156 {
141157 return [
142158 'date ' => $ date ,
143- 'occurrences ' => $ occurrences ->map (function (Entry $ occurrence ) use ($ date ): Entry {
144- if (!$ occurrence ->spanning ) {
145- return $ occurrence ;
146- }
147-
148- $ carbonDate = Carbon::parse ($ date )->shiftTimezone ($ occurrence ->start ->timezone );
149- $ occurrence
150- ->setSupplement ('spanning_start ' , $ occurrence ->start ->isSameDay ($ carbonDate ))
151- ->setSupplement ('spanning_end ' , $ occurrence ->end ->isSameDay ($ carbonDate ));
152-
153- return clone $ occurrence ;
154- })->values (),
159+ 'occurrences ' => $ this ->addSpanningStartEnd ($ date , $ occurrences ),
155160 ];
156161 }
157162
@@ -263,7 +268,7 @@ private function spanningDays(): Closure
263268 $ occurrence ->end ->endOfDay ()
264269 )->toArray ();
265270
266- return collect ($ spanningDays )->map (fn (CarbonImmutable $ date ) => $ date ->toDateString ())->all ();
271+ return collect ($ spanningDays )->map (fn (CarbonImmutable $ date ) => $ date ->toDateString ())->all ();
267272 };
268273 }
269274}
0 commit comments