From 7de2f7cf7351c2420d0774d7a19537e061713dd0 Mon Sep 17 00:00:00 2001 From: mistic100 Date: Wed, 29 Jan 2014 20:50:58 +0000 Subject: Merged revision(s) 27043 from trunk: str2DateTime return false on empty input git-svn-id: http://piwigo.org/svn/branches/2.6@27044 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/functions.inc.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/include/functions.inc.php b/include/functions.inc.php index 1e2b1486f..a08bd94b4 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -544,7 +544,12 @@ function dateDiff($date1, $date2) */ function str2DateTime($original, $format=null) { - if ( !empty($format) && version_compare(PHP_VERSION, '5.3.0') >= 0 )// from known date format + if (empty($original)) + { + return false; + } + + if (!empty($format) && version_compare(PHP_VERSION, '5.3.0') >= 0)// from known date format { return DateTime::createFromFormat('!'.$format, $original); // ! char to reset fields to UNIX epoch } @@ -553,7 +558,7 @@ function str2DateTime($original, $format=null) $t = trim($original, '0123456789'); if (empty($t)) // from timestamp { - $date = new DateTime('@'.$original); + return new DateTime('@'.$original); } else // from unknown date format (assuming something like Y-m-d H:i:s) { @@ -573,9 +578,8 @@ function str2DateTime($original, $format=null) $date = new DateTime(); $date->setDate($ymdhms[0], $ymdhms[1], $ymdhms[2]); $date->setTime($ymdhms[3], $ymdhms[4], $ymdhms[5]); + return $date; } - - return $date; } } -- cgit v1.2.3