Skip to content

Commit efafe1d

Browse files
committed
Show times for display timezone
In the dropdown menu in the rotation config form show times in the display timezone in parentheses next to the normal time (schedule timezone).
1 parent 0b0b74e commit efafe1d

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

application/controllers/ScheduleController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function addRotationAction(): void
133133
$this->addContent(new TimezoneWarning($scheduleTimezone));
134134
}
135135

136-
$form = new RotationConfigForm($scheduleId, Database::get());
136+
$form = new RotationConfigForm($scheduleId, Database::get(), $displayTimezone);
137137
$form->setAction($this->getRequest()->getUrl()->setParam('showCompact')->getAbsoluteUrl());
138138
$form->setSuggestionUrl(Url::fromPath('notifications/schedule/suggest-recipient'));
139139
$form->on(RotationConfigForm::ON_SENT, function ($form) {
@@ -173,7 +173,7 @@ public function editRotationAction(): void
173173
$this->addContent(new TimezoneWarning($scheduleTimezone));
174174
}
175175

176-
$form = new RotationConfigForm($scheduleId, Database::get());
176+
$form = new RotationConfigForm($scheduleId, Database::get(), $displayTimezone);
177177
$form->disableModeSelection();
178178
$form->setShowRemoveButton();
179179
$form->loadRotation($id);

application/forms/RotationConfigForm.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ class RotationConfigForm extends CompatForm
8080
/** @var int The rotation id */
8181
protected $rotationId;
8282

83+
/** @var string The timezone to display the timeline in */
84+
protected $displayTimezone;
85+
8386
/**
8487
* Set the label for the submit button
8588
*
@@ -187,11 +190,13 @@ public function hasBeenWiped(): bool
187190
*
188191
* @param int $scheduleId
189192
* @param Connection $db
193+
* @param string $displayTimezone
190194
*/
191-
public function __construct(int $scheduleId, Connection $db)
195+
public function __construct(int $scheduleId, Connection $db, string $displayTimezone)
192196
{
193197
$this->db = $db;
194198
$this->scheduleId = $scheduleId;
199+
$this->displayTimezone = $displayTimezone;
195200
}
196201

197202
/**
@@ -1300,12 +1305,25 @@ private function getTimeOptions(): array
13001305
\IntlDateFormatter::SHORT
13011306
);
13021307

1308+
$dtzFormatter = new \IntlDateFormatter(
1309+
\Locale::getDefault(),
1310+
\IntlDateFormatter::NONE,
1311+
\IntlDateFormatter::SHORT,
1312+
$this->displayTimezone
1313+
);
1314+
13031315
$options = [];
1304-
$dt = new DateTime();
1316+
$dt = new DateTime('now', new DateTimeZone($this->getScheduleTimezone()));
13051317
for ($hour = 0; $hour < 24; $hour++) {
13061318
for ($minute = 0; $minute < 60; $minute += 30) {
13071319
$dt->setTime($hour, $minute);
1308-
$options[$dt->format('H:i')] = $formatter->format($dt);
1320+
$dtzDt = (clone $dt)->setTimezone(new DateTimeZone($this->displayTimezone));
1321+
1322+
$options[$dt->format('H:i')] = sprintf(
1323+
'%s (%s)',
1324+
$formatter->format($dt),
1325+
$dtzFormatter->format($dtzDt)
1326+
);
13091327
}
13101328
}
13111329

0 commit comments

Comments
 (0)