diff --git a/application/Espo/Core/Repositories/Event.php b/application/Espo/Core/Repositories/Event.php index 0546a03d9e..5d4b60401a 100644 --- a/application/Espo/Core/Repositories/Event.php +++ b/application/Espo/Core/Repositories/Event.php @@ -251,15 +251,17 @@ class Event extends \Espo\Core\ORM\Repositories\RDB protected function convertDateTimeToDefaultTimezone($string) { - $dateTime = \DateTime::createFromFormat($this->getDateTime()->getInternalDateTimeFormat(), $string); - $timeZone = $this->getConfig()->get('timeZone'); - if (empty($timeZone)) { - $timeZone = 'UTC'; - } - $tz = $timezone = new \DateTimeZone($timeZone); + $timeZone = $this->getConfig()->get('timeZone') ?? 'UTC'; - if ($dateTime) { - return $dateTime->setTimezone($tz)->format($this->getDateTime()->getInternalDateTimeFormat()); + $tz = new \DateTimeZone($timeZone); + + try { + $dt = \DateTime::createFromFormat($this->getDateTime()->getInternalDateTimeFormat(), $string, $tz); + } catch (\Exception $e) {} + + if ($dt) { + $utcTz = new \DateTimeZone('UTC'); + return $dt->setTimezone($utcTz)->format($this->getDateTime()->getInternalDateTimeFormat()); } return null; }