-
backend/app/Helper/DateHelper.php
Open in GitHubuse Carbon\Carbon; class DateHelper { public static function convertToUTC(string $eventDate, string $userTimezone): string { return Carbon::parse($eventDate, $userTimezone) ->setTimezone('UTC') ->toString(); } public static function convertFromUTC(string $eventDate, string $userTimezone): string { return Carbon::parse($eventDate, 'UTC') ->setTimezone($userTimezone) ->toString(); } public static function utcDateIsPast(string $eventDate): bool { return Carbon::parse($eventDate, 'UTC')->isPast(); } public static function utcDateIsFuture(string $eventDate): bool { return Carbon::parse($eventDate, 'UTC')->isFuture(); } }
-
backend/app/Services/Handlers/Event/UpdateEventHandler.php
Open in GitHubuse HiEvents\Helper\DateHelper; use HiEvents\Services\Handlers\Event\DTO\UpdateEventDTO; readonly class UpdateEventHandler { // ... private function updateEventAttributes(UpdateEventDTO $eventData): void { $existingEvent = $this->fetchExistingEvent($eventData); if ($eventData->currency !== null && $eventData->currency !== $existingEvent->getCurrency()) { $this->checkForCompletedOrders($eventData); } $this->eventRepository->updateWhere( attributes: [ 'title' => $eventData->title, 'start_date' => DateHelper::convertToUTC($eventData->start_date, $eventData->timezone), 'end_date' => $eventData->end_date ? DateHelper::convertToUTC($eventData->end_date, $eventData->timezone) : null, 'description' => $this->purifier->purify($eventData->description), 'timezone' => $eventData->timezone ?? $existingEvent->getTimezone(), 'currency' => $eventData->currency ?? $existingEvent->getCurrency(), 'location' => $eventData->location, 'location_details' => $eventData->location_details?->toArray(), ], where: [ 'id' => $eventData->id, 'account_id' => $eventData->account_id, ], ); } // ... }