Skip to content

Commit

Permalink
fixup! fix: appointment slots start and end time
Browse files Browse the repository at this point in the history
Signed-off-by: SebastianKrupinski <[email protected]>
  • Loading branch information
SebastianKrupinski committed Nov 18, 2024
1 parent a06a01c commit 909c0c8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/Controller/BookingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
namespace OCA\Calendar\Controller;

use DateTime;
use DateTimeImmutable;
use DateTimeZone;
use InvalidArgumentException;
Expand Down Expand Up @@ -89,17 +90,20 @@ public function __construct(string $appName,
public function getBookableSlots(int $appointmentConfigId,
int $startTime,
string $timeZone): JsonResponse {
// Convert the timestamps to the beginning and end of the respective day in the specified timezone
try {
$tz = new DateTimeZone($timeZone);
} catch (Exception $e) {
$this->logger->error('Timezone invalid', ['exception' => $e]);
return JsonResponse::fail('Invalid time zone', Http::STATUS_UNPROCESSABLE_ENTITY);
}

$startTimeInTz = (new DateTimeImmutable("@$startTime", $tz))
// UI sends epoch start of day adjusted for system users calendar
// E.g "Mon, 18 Nov 2024 05:00:00 +0000" (America/Toronto)
$startDate = (new DateTimeImmutable("@$startTime"));
// Convert start date to requesters selected timezone adjusted start and end of day in epoch
// E.g "Mon, 18 Nov 2024 06:00:00 +0000" (America/Mexico_City)
$startTimeInTz = (new DateTime($startDate->format('Y-m-d'), $tz))
->getTimestamp();
$endTimeInTz = (new DateTimeImmutable("@$startTime", $tz))
$endTimeInTz = (new DateTime($startDate->format('Y-m-d'), $tz))
->modify('+1 day')
->getTimestamp();

Expand Down

0 comments on commit 909c0c8

Please sign in to comment.