mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-28 19:03:21 +03:00
Corrected timezone support when syncing events with Google Calendar
This commit is contained in:
parent
022644b59e
commit
cc44f3e0c6
2 changed files with 21 additions and 15 deletions
|
@ -151,12 +151,14 @@ class Google_Sync {
|
||||||
$event->setDescription($appointment['notes']);
|
$event->setDescription($appointment['notes']);
|
||||||
$event->setLocation(isset($appointment['location']) ? $appointment['location'] : $settings['company_name']);
|
$event->setLocation(isset($appointment['location']) ? $appointment['location'] : $settings['company_name']);
|
||||||
|
|
||||||
|
$timezone = new DateTimeZone($provider['timezone']);
|
||||||
|
|
||||||
$start = new Google_Service_Calendar_EventDateTime();
|
$start = new Google_Service_Calendar_EventDateTime();
|
||||||
$start->setDateTime(date3339(strtotime($appointment['start_datetime'])));
|
$start->setDateTime((new DateTime($appointment['start_datetime'], $timezone))->format(DateTime::RFC3339));
|
||||||
$event->setStart($start);
|
$event->setStart($start);
|
||||||
|
|
||||||
$end = new Google_Service_Calendar_EventDateTime();
|
$end = new Google_Service_Calendar_EventDateTime();
|
||||||
$end->setDateTime(date3339(strtotime($appointment['end_datetime'])));
|
$end->setDateTime((new DateTime($appointment['end_datetime'], $timezone))->format(DateTime::RFC3339));
|
||||||
$event->setEnd($end);
|
$event->setEnd($end);
|
||||||
|
|
||||||
$event->attendees = [];
|
$event->attendees = [];
|
||||||
|
@ -170,8 +172,7 @@ class Google_Sync {
|
||||||
if ($customer != NULL)
|
if ($customer != NULL)
|
||||||
{
|
{
|
||||||
$event_customer = new Google_Service_Calendar_EventAttendee();
|
$event_customer = new Google_Service_Calendar_EventAttendee();
|
||||||
$event_customer->setDisplayName($customer['first_name'] . ' '
|
$event_customer->setDisplayName($customer['first_name'] . ' ' . $customer['last_name']);
|
||||||
. $customer['last_name']);
|
|
||||||
$event_customer->setEmail($customer['email']);
|
$event_customer->setEmail($customer['email']);
|
||||||
$event->attendees[] = $event_customer;
|
$event->attendees[] = $event_customer;
|
||||||
}
|
}
|
||||||
|
@ -207,19 +208,20 @@ class Google_Sync {
|
||||||
$event->setDescription($appointment['notes']);
|
$event->setDescription($appointment['notes']);
|
||||||
$event->setLocation(isset($appointment['location']) ? $appointment['location'] : $settings['company_name']);
|
$event->setLocation(isset($appointment['location']) ? $appointment['location'] : $settings['company_name']);
|
||||||
|
|
||||||
|
$timezone = new DateTimeZone($provider['timezone']);
|
||||||
|
|
||||||
$start = new Google_Service_Calendar_EventDateTime();
|
$start = new Google_Service_Calendar_EventDateTime();
|
||||||
$start->setDateTime(date3339(strtotime($appointment['start_datetime'])));
|
$start->setDateTime((new DateTime($appointment['start_datetime'], $timezone))->format(DateTime::RFC3339));
|
||||||
$event->setStart($start);
|
$event->setStart($start);
|
||||||
|
|
||||||
$end = new Google_Service_Calendar_EventDateTime();
|
$end = new Google_Service_Calendar_EventDateTime();
|
||||||
$end->setDateTime(date3339(strtotime($appointment['end_datetime'])));
|
$end->setDateTime((new DateTime($appointment['end_datetime'], $timezone))->format(DateTime::RFC3339));
|
||||||
$event->setEnd($end);
|
$event->setEnd($end);
|
||||||
|
|
||||||
$event->attendees = [];
|
$event->attendees = [];
|
||||||
|
|
||||||
$event_provider = new Google_Service_Calendar_EventAttendee();
|
$event_provider = new Google_Service_Calendar_EventAttendee();
|
||||||
$event_provider->setDisplayName($provider['first_name'] . ' '
|
$event_provider->setDisplayName($provider['first_name'] . ' ' . $provider['last_name']);
|
||||||
. $provider['last_name']);
|
|
||||||
$event_provider->setEmail($provider['email']);
|
$event_provider->setEmail($provider['email']);
|
||||||
$event->attendees[] = $event_provider;
|
$event->attendees[] = $event_provider;
|
||||||
|
|
||||||
|
@ -273,12 +275,14 @@ class Google_Sync {
|
||||||
$event->setSummary('Unavailable');
|
$event->setSummary('Unavailable');
|
||||||
$event->setDescription($unavailable['notes']);
|
$event->setDescription($unavailable['notes']);
|
||||||
|
|
||||||
|
$timezone = new DateTimeZone($provider['timezone']);
|
||||||
|
|
||||||
$start = new Google_Service_Calendar_EventDateTime();
|
$start = new Google_Service_Calendar_EventDateTime();
|
||||||
$start->setDateTime(date3339(strtotime($unavailable['start_datetime'])));
|
$start->setDateTime((new DateTime($unavailable['start_datetime'], $timezone))->format(DateTime::RFC3339));
|
||||||
$event->setStart($start);
|
$event->setStart($start);
|
||||||
|
|
||||||
$end = new Google_Service_Calendar_EventDateTime();
|
$end = new Google_Service_Calendar_EventDateTime();
|
||||||
$end->setDateTime(date3339(strtotime($unavailable['end_datetime'])));
|
$end->setDateTime((new DateTime($unavailable['end_datetime'], $timezone))->format(DateTime::RFC3339));
|
||||||
$event->setEnd($end);
|
$event->setEnd($end);
|
||||||
|
|
||||||
// Add the new event to the google calendar.
|
// Add the new event to the google calendar.
|
||||||
|
@ -304,12 +308,14 @@ class Google_Sync {
|
||||||
$unavailable['id_google_calendar']);
|
$unavailable['id_google_calendar']);
|
||||||
$event->setDescription($unavailable['notes']);
|
$event->setDescription($unavailable['notes']);
|
||||||
|
|
||||||
|
$timezone = new DateTimeZone($provider['timezone']);
|
||||||
|
|
||||||
$start = new Google_Service_Calendar_EventDateTime();
|
$start = new Google_Service_Calendar_EventDateTime();
|
||||||
$start->setDateTime(date3339(strtotime($unavailable['start_datetime'])));
|
$start->setDateTime((new DateTime($unavailable['start_datetime'], $timezone))->format(DateTime::RFC3339));
|
||||||
$event->setStart($start);
|
$event->setStart($start);
|
||||||
|
|
||||||
$end = new Google_Service_Calendar_EventDateTime();
|
$end = new Google_Service_Calendar_EventDateTime();
|
||||||
$end->setDateTime(date3339(strtotime($unavailable['end_datetime'])));
|
$end->setDateTime((new DateTime($unavailable['end_datetime'], $timezone))->format(DateTime::RFC3339));
|
||||||
$event->setEnd($end);
|
$event->setEnd($end);
|
||||||
|
|
||||||
$updated_event = $this->service->events->update($provider['settings']['google_calendar'],
|
$updated_event = $this->service->events->update($provider['settings']['google_calendar'],
|
||||||
|
@ -364,8 +370,8 @@ class Google_Sync {
|
||||||
$this->CI->load->helper('general');
|
$this->CI->load->helper('general');
|
||||||
|
|
||||||
$params = [
|
$params = [
|
||||||
'timeMin' => date3339($start),
|
'timeMin' => date(DateTime::RFC3339, $start),
|
||||||
'timeMax' => date3339($end),
|
'timeMax' => date(DateTime::RFC3339, $end),
|
||||||
'singleEvents' => TRUE,
|
'singleEvents' => TRUE,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -551,7 +551,7 @@ class Timezones {
|
||||||
*/
|
*/
|
||||||
public function convert($value, $from_timezone, $to_timezone)
|
public function convert($value, $from_timezone, $to_timezone)
|
||||||
{
|
{
|
||||||
if ( ! $to_timezone)
|
if ( ! $to_timezone || $from_timezone === $to_timezone)
|
||||||
{
|
{
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue