From 03cc220380c874a7dacda8d3a5b8a1ed949e1760 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Fri, 29 Apr 2022 18:29:17 +0200 Subject: [PATCH] getReadableDate() returns empty string if emptry string or null is passed --- inc/inc.Utils.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/inc/inc.Utils.php b/inc/inc.Utils.php index 15d43be93..2d8a850f7 100644 --- a/inc/inc.Utils.php +++ b/inc/inc.Utils.php @@ -41,12 +41,23 @@ function getConvertDateFormat() { /* {{{ */ return 'yyyy-mm-dd'; } /* }}} */ +/** + * Return a human readable date string + * + * This function formats a timestamp according to the date format + * settings. If no timestamp is passed the current date is used. + * If null or an empty string is passed, then an empty string + * is returned. If $timestamp is numeric it will be taken as a unix + * timestamp. If $timestamp is a string it will be parҕed with strtotime(). + */ function getReadableDate($timestamp=0) { /* {{{ */ global $settings; - if(!$timestamp) + if($timestamp === 0) $timestamp = time(); - elseif(!is_numeric($timestamp)) + elseif($timestamp && is_string($timestamp)) $timestamp = strtotime($timestamp); + elseif(!is_numeric($timestamp)) + return ''; if($settings->_dateformat) return date($settings->_dateformat, $timestamp); else