|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
prossel Smarty n00b
Joined: 08 Aug 2003 Posts: 4 Location: Switzerland
|
Posted: Thu Mar 18, 2004 5:29 pm Post subject: smarty_make_timestamp: wrong result with MySQL timestamps |
|
|
I've run into some cases where smarty_make_timestamp returns wrong results with some values of MySQL timestamps.
Example:
Real date: march 18th, 2004 17:37:49
MySQL timestamp value: 20040318173749
Smarty template: {$EditDate|date_format:"%b %d, %Y %H:%M:%S"}
result: Jun 13, 1977 00:00:00
So where is the problem ?
By debugging smarty_make_timestamp() function, it turns out that strtotime() of this value is returning something that is_numeric() so it is returned. That means the special mysql timestamp case is not handled as it comes after the return.
I suggest the function sould be modified as below. It seems to work for me, but I let you appreciate if it is relevant:
Please advise.
Thank you.
Pierre Rossel
proposition of code modification in shared.make_timestamp.php:
Code: |
function smarty_make_timestamp($string)
{
if(empty($string)) {
$string = "now";
}
// 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;
}
$time = strtotime($string);
if (is_numeric($time) && $time != -1)
return $time;
// couldn't recognize it, try to return a time
$time = (int) $string;
if ($time > 0)
return $time;
else
return time();
}
|
|
|
Back to top |
|
williamvee Smarty Rookie
Joined: 01 Aug 2003 Posts: 7 Location: Netherlands
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|