Skip to content

Commit ce238a8

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 82d0bfd commit ce238a8

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
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: 30 additions & 4 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
/**
@@ -1294,18 +1299,39 @@ private function parseDateAndTime(?string $date = null, ?string $time = null): D
12941299
*/
12951300
private function getTimeOptions(): array
12961301
{
1302+
$scheduleTimezone = $this->getScheduleTimezone();
1303+
12971304
$formatter = new \IntlDateFormatter(
12981305
\Locale::getDefault(),
12991306
\IntlDateFormatter::NONE,
1300-
\IntlDateFormatter::SHORT
1307+
\IntlDateFormatter::SHORT,
1308+
$scheduleTimezone->getName()
1309+
);
1310+
1311+
$dtzFormatter = new \IntlDateFormatter(
1312+
\Locale::getDefault(),
1313+
\IntlDateFormatter::NONE,
1314+
\IntlDateFormatter::SHORT,
1315+
$this->displayTimezone
13011316
);
13021317

13031318
$options = [];
1304-
$dt = new DateTime();
1319+
$dt = new DateTime('now', $scheduleTimezone);
13051320
for ($hour = 0; $hour < 24; $hour++) {
13061321
for ($minute = 0; $minute < 60; $minute += 30) {
13071322
$dt->setTime($hour, $minute);
1308-
$options[$dt->format('H:i')] = $formatter->format($dt);
1323+
1324+
if ($this->displayTimezone !== $scheduleTimezone->getName()) {
1325+
$dtzDt = (clone $dt)->setTimezone(new DateTimeZone($this->displayTimezone));
1326+
1327+
$options[$dt->format('H:i')] = sprintf(
1328+
'%s (%s)',
1329+
$formatter->format($dt),
1330+
$dtzFormatter->format($dtzDt)
1331+
);
1332+
} else {
1333+
$options[$dt->format('H:i')] = $formatter->format($dt);
1334+
}
13091335
}
13101336
}
13111337

0 commit comments

Comments
 (0)