get('proIds'); $start = $request->get('start'); $end = $request->get('end'); $timeZone = $request->get('timeZone'); $appointments = Appointment ::whereIn('pro_id', explode(',', $proIds)) ->where('status', '!=', 'COMPLETED') ->where('status', '!=', 'CANCELLED') ->where('start_time', '>=', $start) ->where('start_time', '<=', $end) ->get(); $events = []; foreach ($appointments as $appointment) { $events[] = [ "title" => '(' . $appointment->pro->initials() . ') ' . $appointment->client->displayName(), "_title" => $appointment->title, "description" => $appointment->description, "clientName" => $appointment->client->displayName(), "appointmentUid" => $appointment->uid, "clientUid" => $appointment->client->uid, "proUid" => $appointment->pro->uid, "start" => $this->convertToTimezone($appointment->start_time, $timeZone), "end" => $this->convertToTimezone($appointment->end_time, $timeZone), "editable" => true ]; } return json_encode($events); } private function convertToTimezone($_dateTime, $_targetTimezone) { if(!$_dateTime) return $_dateTime; $timezone = 'US/Eastern'; switch($_targetTimezone) { case 'ALASKA': $timezone = "US/Alaska"; break; case 'CENTRAL': $timezone = "US/Central"; break; case 'HAWAII': $timezone = "US/Hawaii"; break; case 'MOUNTAIN': $timezone = "US/Mountain"; break; case 'PACIFIC': $timezone = "US/Pacific"; break; case 'PUERTO_RICO': $timezone = "America/Puerto_Rico"; break; default: $timezone = "US/Eastern"; break; } $date = new \DateTime($_dateTime, new \DateTimeZone("UTC")); $date->setTimezone(new \DateTimeZone($timezone)); return $date->format('Y-m-d H:i:s'); } }