Skip to content

Commit 588bea7

Browse files
committed
Add fix
1 parent 2034b4e commit 588bea7

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

‎src/Types/Event.php‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use RRule\RRuleInterface;
1212
use Spatie\IcalendarGenerator\Components\Event as ICalendarEvent;
1313
use Statamic\Entries\Entry;
14+
use TransformStudios\Events\Events;
1415

1516
abstract class Event
1617
{
@@ -87,14 +88,14 @@ public function startTime(): string
8788
public function start(): CarbonImmutable
8889
{
8990
return CarbonImmutable::parse($this->start_date)
90-
->shiftTimezone($this->timezone['name'])
91+
->shiftTimezone($this->timezoneName())
9192
->setTimeFromTimeString($this->startTime());
9293
}
9394

9495
public function end(): CarbonImmutable
9596
{
9697
return CarbonImmutable::parse($this->start_date)
97-
->shiftTimezone($this->timezone['name'])
98+
->shiftTimezone($this->timezoneName())
9899
->setTimeFromTimeString($this->endTime());
99100
}
100101

@@ -165,14 +166,19 @@ protected function toCarbonImmutable(string|CarbonInterface $date): CarbonImmuta
165166
{
166167
$carbon = is_string($date) ? CarbonImmutable::parse($date) : $date;
167168

168-
return $carbon->shiftTimezone($this->timezone['name']);
169+
return $carbon->shiftTimezone($this->timezoneName());
170+
}
171+
172+
protected function timezoneName(): string
173+
{
174+
return Arr::get($this->timezone->data(), 'name') ?? Events::defaultTimezone();
169175
}
170176

171177
private function collect(array $dates): Collection
172178
{
173179
return collect($dates)
174180
->map(fn (DateTimeInterface $date) => $this->supplement(
175-
date: CarbonImmutable::parse($date, $this->timezone['name'])
181+
date: CarbonImmutable::parse($date, $this->timezoneName())
176182
))->filter();
177183
}
178184
}

‎src/Types/MultiDayEvent.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct(Entry $event, private bool $collapseMultiDays)
2525
->sortBy('date')
2626
->map(fn (Values $day) => new Day(
2727
$day->all(),
28-
$this->timezone['name'],
28+
$this->timezoneName(),
2929
$day->all_day || $this->isAllDay(),
3030
));
3131
}

‎src/Types/RecurringEvent.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected function rule(bool $useEnd = false): RRuleInterface
6161
];
6262

6363
if ($end = $this->end_date) {
64-
$rule['until'] = CarbonImmutable::parse($end)->shiftTimezone($this->timezone['name'])->endOfDay();
64+
$rule['until'] = CarbonImmutable::parse($end)->shiftTimezone($this->timezoneName())->endOfDay();
6565
}
6666

6767
if (! empty($days = $this->onSpecificDays())) {

0 commit comments

Comments
 (0)