Skip to content

Commit d60c04c

Browse files
committed
Use schedule timezone for RotationConfigForm
Use the schedule timezone to configure rotations. All times entered are handled in the schedule timezone.
1 parent c45ffb4 commit d60c04c

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

application/forms/RotationConfigForm.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
use DateInterval;
88
use DateTime;
9+
use DateTimeZone;
910
use Generator;
1011
use Icinga\Exception\ConfigurationError;
1112
use Icinga\Exception\Http\HttpNotFoundException;
1213
use Icinga\Module\Notifications\Common\Database;
1314
use Icinga\Module\Notifications\Model\Contact;
1415
use Icinga\Module\Notifications\Model\Contactgroup;
1516
use Icinga\Module\Notifications\Model\Rotation;
17+
use Icinga\Module\Notifications\Model\Schedule;
1618
use Icinga\Module\Notifications\Model\TimeperiodEntry;
1719
use Icinga\Util\Json;
1820
use Icinga\Web\Session;
@@ -1145,7 +1147,8 @@ function ($value, $validator) use ($earliestHandoff, $firstHandoff, $latestHando
11451147
(new \IntlDateFormatter(
11461148
\Locale::getDefault(),
11471149
\IntlDateFormatter::MEDIUM,
1148-
\IntlDateFormatter::SHORT
1150+
\IntlDateFormatter::SHORT,
1151+
$this->getScheduleTimezone()
11491152
))->format($actualFirstHandoff)
11501153
);
11511154
}
@@ -1270,7 +1273,8 @@ private function parseDateAndTime(?string $date = null, ?string $time = null): D
12701273
return (new DateTime())->setTime(0, 0);
12711274
}
12721275

1273-
$datetime = DateTime::createFromFormat($format, $expression);
1276+
$datetime = DateTime::createFromFormat($format, $expression, new DateTimeZone($this->getScheduleTimezone()));
1277+
12741278
if ($datetime === false) {
12751279
$datetime = (new DateTime())->setTime(0, 0);
12761280
} elseif ($time === null) {
@@ -1665,4 +1669,17 @@ public function hasChanges(): bool
16651669

16661670
return ! empty(array_udiff_assoc($values, $dbValuesToCompare, $checker));
16671671
}
1672+
1673+
/**
1674+
* Get the timezone of the schedule
1675+
*
1676+
* @return string The timezone identifier
1677+
*/
1678+
protected function getScheduleTimezone(): string
1679+
{
1680+
return Schedule::on(Database::get())
1681+
->filter(Filter::equal('id', $this->scheduleId))
1682+
->first()
1683+
->timezone;
1684+
}
16681685
}

0 commit comments

Comments
 (0)