1
0
mirror of https://github.com/dwaxweiler/connector-mobilizon synced 2025-06-05 21:59:25 +02:00

let frontend dates and times be formatted by backend before sending

This commit is contained in:
Daniel Waxweiler
2025-05-28 10:20:57 +02:00
parent 1c3ea8462e
commit 108e677abe
9 changed files with 54 additions and 197 deletions

View File

@@ -43,6 +43,7 @@ class Api {
} else {
$events = GraphQlClient::get_upcoming_events($url, (int) $eventsCount);
}
$events = array_map([self::class, 'addDateAndTimeFormats'], $events);
return $events;
} catch (GeneralException $e) {
return new \WP_Error('events_not_loading', 'The events could not be loaded!', array('status' => 500));
@@ -50,4 +51,21 @@ class Api {
return new \WP_Error('group_not_found', sprintf('The group "%s" could not be found!', $groupName), array('status' => 404));
}
}
public static function addDateAndTimeFormats($event) {
$dateFormat = SiteSettings::getDateFormat();
$timeFormat = SiteSettings::getTimeFormat();
$timeZone = SiteSettings::getTimeZone();
$startDateTime = new LocalDateTime($event['beginsOn'], $timeZone);
$event['startDateFormatted'] = LocalDateTimeFormatter::format($startDateTime, $dateFormat);
$event['startTimeFormatted'] = LocalDateTimeFormatter::format($startDateTime, $timeFormat);
if ($event['endsOn']) {
$endDateTime = new LocalDateTime($event['endsOn'], $timeZone);
$event['endDateFormatted'] = LocalDateTimeFormatter::format($endDateTime, $dateFormat);
$event['endTimeFormatted'] = LocalDateTimeFormatter::format($endDateTime, $timeFormat);
}
return $event;
}
}