mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 03:14:27 +02:00
removed ambiguity for numeric values passed to smarty_make_timestamp().
numeric values are *always* treated as timestamps now.
This commit is contained in:
3
NEWS
3
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)
|
||||
|
@@ -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: */
|
||||
|
Reference in New Issue
Block a user