aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormistic100 <mistic@piwigo.org>2014-01-29 20:49:19 +0000
committermistic100 <mistic@piwigo.org>2014-01-29 20:49:19 +0000
commit8a8c8c161db8d9891112a766a5f1fa6cc41c0dd1 (patch)
tree67df87bdfb4c4d04bbb720e88e4575e31c027e70
parentfe98d56e38a464fe15a02f716bb196ad771b410f (diff)
str2DateTime return false on empty input
git-svn-id: http://piwigo.org/svn/trunk@27043 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--include/functions.inc.php12
1 files 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;
}
}