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

shared.make_timestamp.php and date_format modifier

 
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
williamvee
Smarty Rookie


Joined: 01 Aug 2003
Posts: 7
Location: Netherlands

PostPosted: Thu Mar 18, 2004 3:38 pm    Post subject: shared.make_timestamp.php and date_format modifier Reply with quote

I've tried this little code in a template:
Code:
{'20040318135500'|date_format:"%a %e %B %Y %H:%M"}


The output I got was:
Fri 3 January 1975 00:00

Although you expect the output to be:
Thu 18 March 2004 13:55

The reason for this problem is that the php function strtotime() thinks that '20040318135500' is a valid time string and converts it into a false timestamp in the shared.make_timestamp.php file.

I've solved the problem by checking the timestring to be a mysql timestamp FIRST. If it's not, then pass it on to the strtotime format. Right now Smarty tries the strtotime function before checking for a mysql timestamp.
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Thu Mar 18, 2004 4:05 pm    Post subject: Reply with quote

what php-version and what operating-system do you use?

the example gives me the "Thu 18 March 2004 13:55" I'd expected.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mohrt
Administrator


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

PostPosted: Thu Mar 18, 2004 4:15 pm    Post subject: Reply with quote

Maybe his strtotime() is throwing back an (incorrect) value instead of an error? I haven't looked at the changelog for strtotime() but that is possible.

A quick fix (and IMHO a good programming practice) is use MySQL's date_format() function to keep MySQL timestamps out of your PHP applications entirely.
Back to top
View user's profile Send private message Visit poster's website
atu
Smarty Regular


Joined: 18 Apr 2003
Posts: 51
Location: Luxembourg

PostPosted: Thu Mar 18, 2004 4:22 pm    Post subject: Reply with quote

Have the same problem in php 4.3.4.
A mysql UNIX_TIMESTAMP(mysql_timestamp) does the job.
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Mar 18, 2004 4:34 pm    Post subject: Reply with quote

@messju: I can verify williamvee's claim on a w2k box, PHP 4.3.4.

edit: yeah, I do the same thing as atu to get around this.
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Thu Mar 18, 2004 4:50 pm    Post subject: Reply with quote

aaah, fscking windows (or is it called scandisking there?). okay.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
williamvee
Smarty Rookie


Joined: 01 Aug 2003
Posts: 7
Location: Netherlands

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

We're using Slackware 8.0 on our development server and FreeBSD 4.9 on the production servers. PHP Version on all locations is 4.3.3.

I would use MySQL's date_format() function if the mysql time stamp wasn't used in like 1000 places in our scripting. The easiest solution I can think of, is to swap the strtotime() and mysql-check in the shared.make_timestamp.php file. Or do you think that changing that could result in having other problems?
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

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

no, I don't think this would cause any big problems.
only a minor performance-hit for people who use *a lot* of calls to date_format with timestamps in their templates.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
williamvee
Smarty Rookie


Joined: 01 Aug 2003
Posts: 7
Location: Netherlands

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

So the next version of Smarty will have this modification..? Or do I have to change it for our company every time a new Smarty is released? Smile
Back to top
View user's profile Send private message
RichardWall
Smarty n00b


Joined: 16 May 2003
Posts: 1

PostPosted: Fri Mar 19, 2004 11:52 am    Post subject: Re: shared.make_timestamp.php and date_format modifier Reply with quote

williamvee wrote:
The reason for this problem is that the php function strtotime() thinks that '20040318135500' is a valid time string and converts it into a false timestamp in the shared.make_timestamp.php file.


I came across this this morning and posted a bug report on php.net...
http://bugs.php.net/bug.php?id=27655

-RichardW.
_________________
--
RichardWall
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