View previous topic :: View next topic |
Author |
Message |
gurubob Smarty Rookie
Joined: 14 Jul 2003 Posts: 8 Location: Hertfordshire, UK
|
Posted: Mon Jul 14, 2003 1:54 pm Post subject: date_format on Win32, missing %e |
|
|
Hi,
It seems that the Win32 implementation of whatever library handles the strftime routine is missing some common format strings, in particular the %e string. This will cause your "date_format"ed dates to show up like:
"July , 2003".
Solution (read: hack) is to open the file modified.date_format.php in the Smarty plugins directory and add these lines after the { on line 15.
/* Win32 Hack for absence of %e format string - note that %d does NOT remove leading 0's, %b does! */
if(eregi('Win32',$_SERVER['SERVER_SOFTWARE'])) { $format = str_replace('%e','%d',$format); }
There are possibly more missing strings, but this will fix the most obvious problem. If someone has a nice solution for removing the leading 0's in a %d, I'd like to see it.
Cheers,
- Bob - |
|
Back to top |
|
alan Smarty Regular
Joined: 17 Apr 2003 Posts: 43
|
Posted: Tue Jul 15, 2003 8:07 pm Post subject: |
|
|
Try (untested) :
Code: |
$result = preg_replace("`0(\d)`", "\1", $source);
|
|
|
Back to top |
|
gurubob Smarty Rookie
Joined: 14 Jul 2003 Posts: 8 Location: Hertfordshire, UK
|
Posted: Tue Jul 15, 2003 9:19 pm Post subject: |
|
|
Magic solution - I was just coding it in and I realised that it would affect codes other than %d as well? If you had a legitimate reason to format a date as dd/mm/yy then dates like 01/02/03 would come out at 1/2/3 ... or did I get it wrong? (hey, it's happened before! ) |
|
Back to top |
|
koejkje Smarty Rookie
Joined: 27 Nov 2003 Posts: 30 Location: Miami, Florida
|
Posted: Sun Jan 04, 2004 3:36 am Post subject: |
|
|
I was actually unable to get this to work in 2.6 even after asjusting the line number. Question is why do we still have this problem in January , 2004? |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Sun Jan 04, 2004 8:54 am Post subject: |
|
|
read the note on http://php.net/strftime .
date_format depends on strftime, strftime depends on the capabilities of your operating system's date-functions. |
|
Back to top |
|
koejkje Smarty Rookie
Joined: 27 Nov 2003 Posts: 30 Location: Miami, Florida
|
Posted: Mon Jan 05, 2004 3:36 am Post subject: |
|
|
Are you suggesting I just assign the current date using PHP and then use smarty to format that? I was thinking I may have to do this anyway due to the cached pages.
Do you have any suggestions for displaying dates that you don't want cached but still would like designers to be able to format with a smarty template? |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Jan 05, 2004 8:41 am Post subject: |
|
|
koejkje wrote: | Do you have any suggestions for displaying dates that you don't want cached but still would like designers to be able to format with a smarty template? |
an insert-function. |
|
Back to top |
|
koejkje Smarty Rookie
Joined: 27 Nov 2003 Posts: 30 Location: Miami, Florida
|
Posted: Sat Jan 10, 2004 12:03 am Post subject: |
|
|
Wouldn't I then be calling a PHP script? I would like the designers to use the Smarty syntax to format the date within a template.
function insert_get_date($array) {
return date("j F, Y");
}
{insert name="get_date"}
function insert_get_year($array) {
return date("Y");
}
{insert name="get_year"}
Thank you for your help. |
|
Back to top |
|
tip Smarty n00b
Joined: 17 Mar 2004 Posts: 2
|
Posted: Wed Mar 17, 2004 1:56 am Post subject: |
|
|
I can propose a patch for modifier.date_format.php:
Unfortunately I don't know how %R should look like, so I didn't include a replacement for it
Code: |
function smarty_modifier_date_format($string, $format="%b %e, %Y", $default_date=null)
{
if (substr(PHP_OS,0,3) == 'WIN') {
$win_from = array ( '%e', '%T', '%D');
$win_to = array ('%#d', '%H:%M:%S', '%m/%d/%y');
$format = str_replace($win_from, $win_to, $format);
}
if($string != '') {
return strftime($format, smarty_make_timestamp($string));
} elseif (isset($default_date) && $default_date != '') {
return strftime($format, smarty_make_timestamp($default_date));
} else {
return;
}
}
|
|
|
Back to top |
|
Ceph Smarty Rookie
Joined: 25 Nov 2003 Posts: 24
|
Posted: Mon May 24, 2004 9:34 pm Post subject: |
|
|
Or you can just use a different date-formatting plugin.
libs/plugins/modifier.date.php
Code: | function smarty_modifier_date( $date, $format = "d/m/Y H:i:s", $default_date_string = "" )
{
if( $date != '' )
{
return date( $format, $date );
}
else
{
return $default_date_string;
}
} |
which allows you to use unix-timestamps as {$mytime|date:"r"} |
|
Back to top |
|
|