diff --git a/application/forms/Announcement/AnnouncementForm.php b/application/forms/Announcement/AnnouncementForm.php index 2caaca0f4..0bc4713cb 100644 --- a/application/forms/Announcement/AnnouncementForm.php +++ b/application/forms/Announcement/AnnouncementForm.php @@ -13,6 +13,21 @@ use Icinga\Forms\RepositoryForm; */ class AnnouncementForm extends RepositoryForm { + protected function fetchEntry() + { + $entry = parent::fetchEntry(); + if ($entry !== false) { + if ($entry->start !== null) { + $entry->start = (new DateTime())->setTimestamp($entry->start); + } + if ($entry->end !== null) { + $entry->end = (new DateTime())->setTimestamp($entry->end); + } + } + + return $entry; + } + /** * {@inheritDoc} */ diff --git a/application/views/scripts/announcements/index.phtml b/application/views/scripts/announcements/index.phtml index 311cfd9da..410e14b02 100644 --- a/application/views/scripts/announcements/index.phtml +++ b/application/views/scripts/announcements/index.phtml @@ -40,8 +40,8 @@ escape($announcement->author) ?> ellipsis($this->escape($announcement->message), 100) ?> - formatDateTime($announcement->start->getTimestamp()) ?> - formatDateTime($announcement->end->getTimestamp()) ?> + formatDateTime($announcement->start) ?> + formatDateTime($announcement->end) ?> hasPermission('admin')): ?> qlink( null, diff --git a/library/Icinga/Web/Announcement/AnnouncementIniRepository.php b/library/Icinga/Web/Announcement/AnnouncementIniRepository.php index ab49021be..12750d11b 100644 --- a/library/Icinga/Web/Announcement/AnnouncementIniRepository.php +++ b/library/Icinga/Web/Announcement/AnnouncementIniRepository.php @@ -30,25 +30,6 @@ class AnnouncementIniRepository extends IniRepository 'end' => 'timestamp' )); - /** - * Create a DateTime from a timestamp - * - * @param string $timestamp - * - * @return DateTime|null - */ - protected function retrieveTimestamp($timestamp) - { - if ($timestamp !== null) { - $dateTime = new DateTime(); - $dateTime->setTimestamp($timestamp); - - return $dateTime; - } - - return null; - } - /** * Get a DateTime's timestamp * @@ -157,7 +138,7 @@ class AnnouncementIniRepository extends IniRepository $refresh = null; foreach ($query as $row) { - $min = min($row->start->getTimestamp(), $row->end->getTimestamp()); + $min = min($row->start, $row->end); if ($refresh === null) { $refresh = $min;