From 9d989890622e6990d62f4c2ce0bdfdef129c36e8 Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Mon, 26 Sep 2022 00:45:17 +0200 Subject: [PATCH] Fix #31: .ICS attachment Convert DateTimeImmutable before trying to format it closes #31 --- calendar.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/calendar.php b/calendar.php index 5debec6..232c10f 100644 --- a/calendar.php +++ b/calendar.php @@ -3180,6 +3180,19 @@ public function itip_event_inviteform($attrib) ) . $hidden->show(); } + /** + * Escape DateTimeImmutableObject to DateTime if necessary + */ + private function sanitize_date_time_immutable($date) + { + $dateclone = clone $date; + if (is_object($dateclone) && is_a($dateclone, 'DateTimeImmutable')) { + return DateTime::createFromImmutable($dateclone); + } else { + return $dateclone; + } + } + /** * */ @@ -3189,8 +3202,8 @@ private function mail_agenda_event_row($event, $class = '') $time = $this->gettext('all-day'); } else { - $start = is_object($event['start']) ? clone $event['start'] : $event['start']; - $end = is_object($event['end']) ? clone $event['end'] : $event['end']; + $start = is_object($event['start']) ? $this->sanitize_date_time_immutable($event['start']) : $event['start']; + $end = is_object($event['end']) ? $this->sanitize_date_time_immutable($event['end']) : $event['end']; $time = $this->rc->format_date($start, $this->rc->config->get('time_format')) . ' - ' . $this->rc->format_date($end, $this->rc->config->get('time_format')); @@ -3259,7 +3272,7 @@ public function mail_messagebody_html($p) // get prepared inline UI for this event object if ($ical_objects->method) { $append = ''; - $date_str = $this->rc->format_date(clone $event['start'], $this->rc->config->get('date_format'), empty($event['start']->_dateonly)); + $date_str = $this->rc->format_date($this->sanitize_date_time_immutable($event['start']), $this->rc->config->get('date_format'), empty($event['start']->_dateonly)); $date = new DateTime($event['start']->format('Y-m-d') . ' 12:00:00', new DateTimeZone('UTC')); // prepare a small agenda preview to be filled with actual event data on async request