Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

smarty_make_timestamp: wrong result with MySQL timestamps

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
prossel
Smarty n00b


Joined: 08 Aug 2003
Posts: 4
Location: Switzerland

PostPosted: Thu Mar 18, 2004 5:29 pm    Post subject: smarty_make_timestamp: wrong result with MySQL timestamps Reply with quote

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
View user's profile Send private message
williamvee
Smarty Rookie


Joined: 01 Aug 2003
Posts: 7
Location: Netherlands

PostPosted: Fri Mar 19, 2004 9:07 am    Post subject: Reply with quote

I agree! Laughing

See the discussion in this thread as well:
http://www.phpinsider.com/smarty-forum/viewtopic.php?t=2184
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP