Skip to content

Commit 113dba3

Browse files
authored
Fix timezone that is not properly set (#246)
Fixes: #231 This fix casts the timezone to a string when setting the timezone so that it is compatible with Google Calendar API specifications: https://developers.google.com/calendar/api/v3/reference/events/insert\#end.timeZone
1 parent 3e5f742 commit 113dba3

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/Event.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,12 @@ protected function setDateProperty(string $name, CarbonInterface $date)
248248

249249
if (in_array($name, ['start.date', 'end.date'])) {
250250
$eventDateTime->setDate($date->format('Y-m-d'));
251-
$eventDateTime->setTimezone($date->getTimezone());
251+
$eventDateTime->setTimezone((string) $date->getTimezone());
252252
}
253253

254254
if (in_array($name, ['start.dateTime', 'end.dateTime'])) {
255255
$eventDateTime->setDateTime($date->format(DateTime::RFC3339));
256-
$eventDateTime->setTimezone($date->getTimezone());
256+
$eventDateTime->setTimezone((string) $date->getTimezone());
257257
}
258258

259259
if (Str::startsWith($name, 'start')) {

tests/Integration/EventTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,14 @@ public function it_can_create_an_event_based_on_a_text_string_statically()
166166

167167
$event::quickCreate('Appointment at Somewhere on April 25 10am-10:25am');
168168
}
169+
170+
/** @test */
171+
public function it_can_set_a_timezone_that_is_a_string()
172+
{
173+
$now = Carbon::now()->setTimezone('Indian/Reunion');
174+
175+
$this->event->endDateTime = $now;
176+
177+
$this->assertEquals((string) $now->getTimezone(), 'Indian/Reunion');
178+
}
169179
}

0 commit comments

Comments
 (0)