removed ambiguity for numeric values passed to smarty_make_timestamp().

numeric values are *always* treated as timestamps now.
This commit is contained in:
messju
2005-07-27 20:54:24 +00:00
parent 559e04911d
commit 51c60e9736
2 changed files with 23 additions and 18 deletions

3
NEWS
View File

@@ -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)

View File

@@ -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: */