Skip to content

Commit a7d121d

Browse files
committed
WIP: Tinkering with timezones
1 parent 08924a5 commit a7d121d

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

src/Tags/Events.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,49 @@ public function calendar(): Collection
4646
return $this->output($this->makeEmptyDates(from: $from, to: $to)->merge($occurrences)->sort()->values());
4747
}
4848

49+
public function calendarWithTimezone(): Collection
50+
{
51+
ray()->clearAll(); // TODO MR: remove
52+
53+
$tempFrom = parse_date('28.02.2026')->shiftTimezone('America/Los_Angeles')->startOfDay();
54+
$tempTo = parse_date('28.02.2026')->shiftTimezone('America/Los_Angeles')->endOfDay();
55+
$temp = $this->generator()->between(from: $tempFrom, to: $tempTo)->first();
56+
57+
$month = $this->params->get('month', now()->englishMonth);
58+
$year = $this->params->get('year', now()->year);
59+
60+
$from = parse_date($month.' '.$year)->startOfMonth()->startOfWeek();
61+
$to = parse_date($month.' '.$year)->endOfMonth()->endOfWeek();
62+
63+
ray([
64+
'start' => $temp->start->format('d.m.Y H:i'),
65+
'end' => $temp->end->format('d.m.Y H:i'),
66+
'startInAppTz' => $temp->start->setTimezone(config('app.timezone'))->format('d.m.Y H:i'),
67+
'endInAppTz' => $temp->end->setTimezone(config('app.timezone'))->format('d.m.Y H:i'),
68+
]); // TODO MR: remove
69+
70+
ray([
71+
'from' => $from->format('d.m.Y H:i'),
72+
'to' => $to->format('d.m.Y H:i'),
73+
]); // TODO MR: remove
74+
75+
$emptyDates = $this->makeEmptyDates(from: $from, to: $to);
76+
77+
$occurrences = $this
78+
->generator()
79+
->between(from: $from, to: $to)
80+
->groupBy(fn (Entry $occurrence) => [
81+
$occurrence->start->setTimezone(config('app.timezone'))->toDateString(),
82+
$occurrence->end->setTimezone(config('app.timezone'))->toDateString(),
83+
])
84+
->map(fn (EntryCollection $occurrences) => $occurrences->unique())
85+
->map(fn (EntryCollection $occurrences, string $date) => $this->day(date: $date, occurrences: $occurrences))
86+
->intersectByKeys($emptyDates)
87+
->ray();
88+
89+
return $this->output($emptyDates->merge($occurrences)->sort()->values());
90+
}
91+
4992
public function downloadLink(): string
5093
{
5194
return route(

0 commit comments

Comments
 (0)