|
7 | 7 | use Carbon\CarbonInterface; |
8 | 8 | use Carbon\CarbonPeriod; |
9 | 9 | use Carbon\CarbonPeriodImmutable; |
| 10 | +use Closure; |
10 | 11 | use Illuminate\Pagination\Paginator; |
11 | 12 | use Illuminate\Support\Collection; |
12 | 13 | use Statamic\Contracts\Query\Builder; |
@@ -41,14 +42,14 @@ public function calendar(): Collection |
41 | 42 | $month = $this->params->get('month', now()->englishMonth); |
42 | 43 | $year = $this->params->get('year', now()->year); |
43 | 44 |
|
44 | | - $from = parse_date($month . ' ' . $year)->startOfMonth()->startOfWeek(); |
45 | | - $to = parse_date($month . ' ' . $year)->endOfMonth()->endOfWeek(); |
| 45 | + $from = parse_date($month.' '.$year)->startOfMonth()->startOfWeek(); |
| 46 | + $to = parse_date($month.' '.$year)->endOfMonth()->endOfWeek(); |
46 | 47 |
|
47 | 48 | $occurrences = $this |
48 | 49 | ->generator() |
49 | 50 | ->between(from: $from, to: $to) |
50 | 51 | ->groupBy($this->spanningDays()) |
51 | | - ->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)); |
52 | 53 |
|
53 | 54 | $days = $this->output($this->makeEmptyDates(from: $from, to: $to)->merge($occurrences)->values()); |
54 | 55 |
|
@@ -139,8 +140,16 @@ private function day(string $date, EntryCollection $occurrences): array |
139 | 140 | { |
140 | 141 | return [ |
141 | 142 | 'date' => $date, |
142 | | - 'dates' => $occurrences, |
143 | | - 'occurrences' => $occurrences, |
| 143 | + 'occurrences' => $occurrences->map(function (Entry $occurrence) use ($date): Entry { |
| 144 | + if ($occurrence->spanning) { |
| 145 | + $carbonDate = Carbon::parse($date)->shiftTimezone($occurrence->start->timezone); |
| 146 | + $occurrence |
| 147 | + ->setSupplement('spanning_start', $occurrence->start->isSameDay($carbonDate)) |
| 148 | + ->setSupplement('spanning_end', $occurrence->end->isSameDay($carbonDate)); |
| 149 | + } |
| 150 | + |
| 151 | + return $occurrence; |
| 152 | + })->values(), |
144 | 153 | ]; |
145 | 154 | } |
146 | 155 |
|
@@ -244,15 +253,15 @@ private function parseTermIds(string $key, array|Builder|string $terms): array |
244 | 253 | ->all(); |
245 | 254 | } |
246 | 255 |
|
247 | | - private function spanningDays(): \Closure |
| 256 | + private function spanningDays(): Closure |
248 | 257 | { |
249 | 258 | return function (Entry $occurrence) { |
250 | 259 | $spanningDays = CarbonPeriodImmutable::between( |
251 | 260 | $occurrence->start->startOfDay(), |
252 | 261 | $occurrence->end->endOfDay() |
253 | 262 | )->toArray(); |
254 | 263 |
|
255 | | - return collect($spanningDays)->map(fn(CarbonImmutable $date) => $date->toDateString())->all(); |
| 264 | + return collect($spanningDays)->map(fn (CarbonImmutable $date) => $date->toDateString())->all(); |
256 | 265 | }; |
257 | 266 | } |
258 | 267 | } |
0 commit comments