Skip to content

Commit

Permalink
Fix PHP8.1 DateTime constructor null time
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
  • Loading branch information
ChristophWurst authored and mrubinsk committed Jun 25, 2022
1 parent 8ea20dc commit ce56b74
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/Horde/Imap/Client/DateTime.php
Expand Up @@ -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) {
Expand All @@ -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 {
Expand All @@ -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);
Expand Down

0 comments on commit ce56b74

Please sign in to comment.