Skip to content

Commit

Permalink
Fix timezone that is not properly set (#246)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tomcodes authored Mar 18, 2022
1 parent 3e5f742 commit 113dba3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ protected function setDateProperty(string $name, CarbonInterface $date)

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

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

if (Str::startsWith($name, 'start')) {
Expand Down
10 changes: 10 additions & 0 deletions tests/Integration/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,14 @@ public function it_can_create_an_event_based_on_a_text_string_statically()

$event::quickCreate('Appointment at Somewhere on April 25 10am-10:25am');
}

/** @test */
public function it_can_set_a_timezone_that_is_a_string()
{
$now = Carbon::now()->setTimezone('Indian/Reunion');

$this->event->endDateTime = $now;

$this->assertEquals((string) $now->getTimezone(), 'Indian/Reunion');
}
}

0 comments on commit 113dba3

Please sign in to comment.