View previous topic :: View next topic |
Author |
Message |
williamvee Smarty Rookie
Joined: 01 Aug 2003 Posts: 7 Location: Netherlands
|
Posted: Thu Mar 18, 2004 3:38 pm Post subject: shared.make_timestamp.php and date_format modifier |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Mar 18, 2004 4:05 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Mar 18, 2004 4:15 pm Post subject: |
|
|
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 |
|
atu Smarty Regular
Joined: 18 Apr 2003 Posts: 51 Location: Luxembourg
|
Posted: Thu Mar 18, 2004 4:22 pm Post subject: |
|
|
Have the same problem in php 4.3.4.
A mysql UNIX_TIMESTAMP(mysql_timestamp) does the job. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu Mar 18, 2004 4:34 pm Post subject: |
|
|
@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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Mar 18, 2004 4:50 pm Post subject: |
|
|
aaah, fscking windows (or is it called scandisking there?). okay. |
|
Back to top |
|
williamvee Smarty Rookie
Joined: 01 Aug 2003 Posts: 7 Location: Netherlands
|
Posted: Fri Mar 19, 2004 9:02 am Post subject: |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Fri Mar 19, 2004 9:09 am Post subject: |
|
|
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 |
|
williamvee Smarty Rookie
Joined: 01 Aug 2003 Posts: 7 Location: Netherlands
|
Posted: Fri Mar 19, 2004 9:30 am Post subject: |
|
|
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? |
|
Back to top |
|
RichardWall Smarty n00b
Joined: 16 May 2003 Posts: 1
|
Posted: Fri Mar 19, 2004 11:52 am Post subject: Re: shared.make_timestamp.php and date_format modifier |
|
|
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 |
|
|