Skip to content

Commit 8c7a7e3

Browse files
ChristophWurstmrubinsk
authored andcommitted
Fix PHP8.1 DateTime constructor null time
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
1 parent ad14710 commit 8c7a7e3

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/Horde/Imap/Client/DateTime.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct($time = null, $tz = null)
3535

3636
/* Bug #14381 Catch malformed offset - which doesn't cause
3737
DateTime to throw exception. */
38-
if (substr(rtrim($time), -5) === ' 0000') {
38+
if ($time !== null && substr(rtrim($time), -5) === ' 0000') {
3939
$time = substr(trim($time), 0, strlen(trim($time)) - 5) . ' +0000';
4040
try {
4141
if ($bug_67118) {
@@ -48,15 +48,15 @@ public function __construct($time = null, $tz = null)
4848

4949
try {
5050
if ($bug_67118) {
51-
new DateTime($time, $tz);
51+
new DateTime($time === null ? 'now' : $time, $tz);
5252
}
53-
parent::__construct($time, $tz);
53+
parent::__construct($time === null ? 'now' : $time, $tz);
5454
return;
5555
} catch (Exception $e) {}
5656

5757
/* Check for malformed day-of-week parts, usually incorrectly
5858
* localized. E.g. Fr, 15 Apr 2016 15:15:09 +0000 */
59-
if (!preg_match("/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun),/", $time)) {
59+
if ($time !== null && !preg_match("/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun),/", $time)) {
6060
$time = preg_replace("/^(\S*,)/", '', $time, 1, $i);
6161
if ($i) {
6262
try {
@@ -70,7 +70,7 @@ public function __construct($time = null, $tz = null)
7070
}
7171

7272
/* Bug #5717 - Check for UT vs. UTC. */
73-
if (substr(rtrim($time), -3) === ' UT') {
73+
if ($time !== null && substr(rtrim($time), -3) === ' UT') {
7474
try {
7575
if ($bug_67118) {
7676
new DateTime($time . 'C', $tz);

0 commit comments

Comments
 (0)