diff --git a/NEWS b/NEWS index 9a544c51..d8dc1ac6 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ + - remove ambiguity for numeric values passed to smarty_make_timestamp() + (and thus the date_format modifier). numeric values are treated as + timestamps now. (andreas, messju) - add passthru attribute feature to html_select_date (Sedgar, monte) - add "middle" parameter to truncate (monte) diff --git a/libs/plugins/shared.make_timestamp.php b/libs/plugins/shared.make_timestamp.php index acdd7773..8d3dc3ad 100644 --- a/libs/plugins/shared.make_timestamp.php +++ b/libs/plugins/shared.make_timestamp.php @@ -16,26 +16,28 @@ function smarty_make_timestamp($string) { if(empty($string)) { - $string = "now"; + // use "now": + $time = time(); + + } 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), + 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; + + } else { + // strtotime should handle it + $time = strtotime($string); + if ($time == -1 || $time === false) { + // strtotime() was not able to parse $string, use "now": + $time = time(); + } } - $time = strtotime($string); - if (is_numeric($time) && $time != -1) - return $time; + return $time; - // is mysql timestamp format of YYYYMMDDHHMMSS? - if (preg_match('/^\d{14}$/', $string)) { - $time = 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)); - - return $time; - } - - // couldn't recognize it, try to return a time - $time = (int) $string; - if ($time > 0) - return $time; - else - return time(); } /* vim: set expandtab: */