From ce56b74290f128be40984d4d89315d64e41f2717 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Mon, 23 May 2022 14:42:37 +0200 Subject: [PATCH] Fix PHP8.1 DateTime constructor null time Signed-off-by: Christoph Wurst --- lib/Horde/Imap/Client/DateTime.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Horde/Imap/Client/DateTime.php b/lib/Horde/Imap/Client/DateTime.php index bc167f28b..a78fb553f 100644 --- a/lib/Horde/Imap/Client/DateTime.php +++ b/lib/Horde/Imap/Client/DateTime.php @@ -35,7 +35,7 @@ public function __construct($time = null, $tz = null) /* Bug #14381 Catch malformed offset - which doesn't cause DateTime to throw exception. */ - if (substr(rtrim($time), -5) === ' 0000') { + if ($time !== null && substr(rtrim($time), -5) === ' 0000') { $time = substr(trim($time), 0, strlen(trim($time)) - 5) . ' +0000'; try { if ($bug_67118) { @@ -48,15 +48,15 @@ public function __construct($time = null, $tz = null) try { if ($bug_67118) { - new DateTime($time, $tz); + new DateTime($time === null ? 'now' : $time, $tz); } - parent::__construct($time, $tz); + parent::__construct($time === null ? 'now' : $time, $tz); return; } catch (Exception $e) {} /* Check for malformed day-of-week parts, usually incorrectly * localized. E.g. Fr, 15 Apr 2016 15:15:09 +0000 */ - if (!preg_match("/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun),/", $time)) { + if ($time !== null && !preg_match("/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun),/", $time)) { $time = preg_replace("/^(\S*,)/", '', $time, 1, $i); if ($i) { try { @@ -70,7 +70,7 @@ public function __construct($time = null, $tz = null) } /* Bug #5717 - Check for UT vs. UTC. */ - if (substr(rtrim($time), -3) === ' UT') { + if ($time !== null && substr(rtrim($time), -3) === ' UT') { try { if ($bug_67118) { new DateTime($time . 'C', $tz);