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

New timestamp format in smarty_make_timestamp()

 
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 -> Feature Requests
View previous topic :: View next topic  
Author Message
gfaieta
Guest





PostPosted: Sat Apr 19, 2003 2:34 pm    Post subject: New timestamp format in smarty_make_timestamp() Reply with quote

As of version 2.5.0 of Smarty the only possible format for timestamps is YYYYMMDDHHMMSS.
MySQL also uses a different format for datetimes YYYY-MM-DD HH:MM:SS so it would be useful to include a parser for such a format too.

Following is a possible code snippet for the new functionality:

Code:

// is mysql datetime format of YYYY-MM-DD HH:MM:SS?
if (ereg( '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$', $string )) {
    $time = mktime(substr($string,11,2),substr($string,14,2),substr($string,17,2),
        substr($string,5,2),substr($string,8,2),substr($string,0,4));

    return $time;
}


Obviously, some optimizations can be used in the code (only allow 0-6 as the first digit for seconds, ...) but it gives a rough idea.

Gianluca
Back to top
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Sat Apr 19, 2003 5:18 pm    Post subject: Reply with quote

smarty_make_timestamp() should be able to take just about any format, is uses strtotime() to parse it. Did you try your format? It should work fine.

Code:

{"2003-04-01 12:33:03"|date_format}


Monte
Back to top
View user's profile Send private message Visit poster's website
gfaieta
Guest





PostPosted: Mon Apr 21, 2003 8:32 am    Post subject: Reply with quote

oops,

you're right. Reading the manual I believed that only unix timestamps and mysql timestamps were accepted; reading the source I didn't find anything new. So I started hacking even before trying.
... strtotime() and similar magic functions ... what a beautiful thing Smile
Maybe, a few more examples in the manual could be useful.

Thanks,
Gianluca
Back to top
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 -> Feature Requests 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