From 50637fccdd7e9d6b67cd3c7cdd132090e6dd61f8 Mon Sep 17 00:00:00 2001 From: "monte.ohrt" Date: Tue, 13 Jul 2010 22:57:47 +0000 Subject: [PATCH] add DateTime support, clean up some logic --- libs/plugins/shared.make_timestamp.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/libs/plugins/shared.make_timestamp.php b/libs/plugins/shared.make_timestamp.php index 4e652ad1..6bef6f25 100644 --- a/libs/plugins/shared.make_timestamp.php +++ b/libs/plugins/shared.make_timestamp.php @@ -18,26 +18,24 @@ function smarty_make_timestamp($string) { if(empty($string)) { // use "now": - $time = time(); - + return time(); + } elseif (is_a($string,'DateTime')) { + return $string->getTimestamp(); } elseif (preg_match('/^\d{14}$/', $string)) { // it is mysql timestamp format of YYYYMMDDHHMMSS? - $time = mktime(substr($string, 8, 2),substr($string, 10, 2),substr($string, 12, 2), + return mktime(substr($string, 8, 2),substr($string, 10, 2),substr($string, 12, 2), substr($string, 4, 2),substr($string, 6, 2),substr($string, 0, 4)); - } elseif (is_numeric($string)) { // it is a numeric string, we handle it as timestamp - $time = (int)$string; - + return (int)$string; } else { // strtotime should handle it $time = strtotime($string); if ($time == -1 || $time === false) { // strtotime() was not able to parse $string, use "now": - $time = time(); + return time(); } + return $time; } - return $time; - } ?>