Skip to content

Commit bcbff3f

Browse files
committed
Session: fix time presentation in /admin/session-list page to apply timezone management - refs BT#23517
1 parent b7b1056 commit bcbff3f

1 file changed

Lines changed: 28 additions & 4 deletions

File tree

src/CoreBundle/Controller/Admin/SessionListController.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,26 @@ public function __construct(
7373
private readonly SettingsManager $settingsManager,
7474
) {}
7575

76+
private function resolvePlatformTimezone(): DateTimeZone
77+
{
78+
$tz = (string) ($this->settingsManager->getSetting('platform.timezone', false, 'timezones') ?? '');
79+
80+
try {
81+
return new DateTimeZone('' !== $tz ? $tz : 'UTC');
82+
} catch (\Throwable) {
83+
return new DateTimeZone('UTC');
84+
}
85+
}
86+
87+
private function formatSessionDate(?DateTime $date, DateTimeZone $tz): ?string
88+
{
89+
if (null === $date) {
90+
return null;
91+
}
92+
93+
return (clone $date)->setTimezone($tz)->format('Y-m-d H:i');
94+
}
95+
7696
#[Route('', name: 'admin_session_list_data', methods: ['GET'])]
7797
public function list(Request $request): JsonResponse
7898
{
@@ -180,14 +200,16 @@ public function list(Request $request): JsonResponse
180200
$tutorsMap = $this->getTutorsBySessionIds($sessionIds);
181201
}
182202

203+
$tz = $this->resolvePlatformTimezone();
204+
183205
$items = [];
184206
foreach ($rows as $row) {
185207
$item = [
186208
'id' => $row['id'],
187209
'title' => $row['title'],
188210
'categoryName' => $row['categoryName'] ?? '',
189-
'displayStartDate' => $row['displayStartDate'] ? $row['displayStartDate']->format('Y-m-d H:i') : null,
190-
'displayEndDate' => $row['displayEndDate'] ? $row['displayEndDate']->format('Y-m-d H:i') : null,
211+
'displayStartDate' => $this->formatSessionDate($row['displayStartDate'], $tz),
212+
'displayEndDate' => $this->formatSessionDate($row['displayEndDate'], $tz),
191213
'visibility' => $row['visibility'],
192214
'visibilityLabel' => self::VISIBILITY_LABELS[$row['visibility']] ?? 'Unknown',
193215
'status' => $row['status'],
@@ -492,14 +514,16 @@ private function enrichWithChildSessions(array $items, bool $showCountUsers): ar
492514
$childTutorsMap = $this->getTutorsBySessionIds($childIds);
493515
}
494516

517+
$tz = $this->resolvePlatformTimezone();
518+
495519
$childMap = [];
496520
foreach ($children as $child) {
497521
$childItem = [
498522
'id' => $child['id'],
499523
'title' => '-- '.$child['title'],
500524
'categoryName' => $child['categoryName'] ?? '',
501-
'displayStartDate' => $child['displayStartDate'] ? $child['displayStartDate']->format('Y-m-d H:i') : null,
502-
'displayEndDate' => $child['displayEndDate'] ? $child['displayEndDate']->format('Y-m-d H:i') : null,
525+
'displayStartDate' => $this->formatSessionDate($child['displayStartDate'], $tz),
526+
'displayEndDate' => $this->formatSessionDate($child['displayEndDate'], $tz),
503527
'visibility' => $child['visibility'],
504528
'visibilityLabel' => self::VISIBILITY_LABELS[$child['visibility']] ?? 'Unknown',
505529
'status' => $child['status'],

0 commit comments

Comments
 (0)