Skip to content

Commit a0917a6

Browse files
committed
Add first handoff hint in the display timezone
Show the first handoff in the display timezone if it differs to the schedule timezone.
1 parent 357f865 commit a0917a6

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

application/forms/RotationConfigForm.php

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ function ($value, $validator) use ($earliestHandoff, $firstHandoff, $latestHando
12421242
if ($actualFirstHandoff < new DateTime()) {
12431243
return $this->translate('The rotation will start immediately');
12441244
} else {
1245-
$handoffHint = sprintf(
1245+
return sprintf(
12461246
$this->translate('The rotation will start on %s'),
12471247
(new \IntlDateFormatter(
12481248
\Locale::getDefault(),
@@ -1251,15 +1251,37 @@ function ($value, $validator) use ($earliestHandoff, $firstHandoff, $latestHando
12511251
$this->scheduleTimezone
12521252
))->format($actualFirstHandoff)
12531253
);
1254-
1255-
if ($this->displayTimezone !== $this->scheduleTimezone) {
1256-
$handoffHint .= sprintf($this->translate(' (in %s)'), $this->scheduleTimezone);
1257-
}
1258-
1259-
return $handoffHint;
12601254
}
12611255
})
12621256
));
1257+
if ($this->displayTimezone !== $this->scheduleTimezone) {
1258+
$this->addHtml(new HtmlElement(
1259+
'p',
1260+
Attributes::create(['id' => 'first-handoff-display-timezone-hint']),
1261+
DeferredText::create(function () {
1262+
$ruleGenerator = $this->yieldRecurrenceRules(1);
1263+
if (! $ruleGenerator->valid()) {
1264+
return '';
1265+
}
1266+
1267+
$actualFirstHandoff = $ruleGenerator->current()[0]->getStartDate();
1268+
if ($actualFirstHandoff < new DateTime()) {
1269+
return '';
1270+
} else {
1271+
return sprintf(
1272+
$this->translate('This would be %s in the chosen display timezone (%s)'),
1273+
(new \IntlDateFormatter(
1274+
\Locale::getDefault(),
1275+
\IntlDateFormatter::MEDIUM,
1276+
\IntlDateFormatter::SHORT,
1277+
$this->displayTimezone
1278+
))->format($actualFirstHandoff),
1279+
$this->displayTimezone,
1280+
);
1281+
}
1282+
})
1283+
));
1284+
}
12631285
}
12641286

12651287
$this->addElement('submit', 'submit', [

public/css/form.less

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@
7070
align-items: baseline;
7171
}
7272

73-
#first-handoff-description {
73+
#first-handoff-description,
74+
#first-handoff-display-timezone-hint {
7475
margin: 0 0 0 14em;
7576
}
7677

0 commit comments

Comments
 (0)