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

date_format on Win32, missing %e

 
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 -> Tips and Tricks
View previous topic :: View next topic  
Author Message
gurubob
Smarty Rookie


Joined: 14 Jul 2003
Posts: 8
Location: Hertfordshire, UK

PostPosted: Mon Jul 14, 2003 1:54 pm    Post subject: date_format on Win32, missing %e Reply with quote

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
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
alan
Smarty Regular


Joined: 17 Apr 2003
Posts: 43

PostPosted: Tue Jul 15, 2003 8:07 pm    Post subject: Reply with quote

Try (untested) :

Code:

$result = preg_replace("`0(\d)`", "\1", $source);
Back to top
View user's profile Send private message
gurubob
Smarty Rookie


Joined: 14 Jul 2003
Posts: 8
Location: Hertfordshire, UK

PostPosted: Tue Jul 15, 2003 9:19 pm    Post subject: Reply with quote

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! Wink )
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
koejkje
Smarty Rookie


Joined: 27 Nov 2003
Posts: 30
Location: Miami, Florida

PostPosted: Sun Jan 04, 2004 3:36 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
messju
Administrator


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

PostPosted: Sun Jan 04, 2004 8:54 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
koejkje
Smarty Rookie


Joined: 27 Nov 2003
Posts: 30
Location: Miami, Florida

PostPosted: Mon Jan 05, 2004 3:36 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
messju
Administrator


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

PostPosted: Mon Jan 05, 2004 8:41 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
koejkje
Smarty Rookie


Joined: 27 Nov 2003
Posts: 30
Location: Miami, Florida

PostPosted: Sat Jan 10, 2004 12:03 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
tip
Smarty n00b


Joined: 17 Mar 2004
Posts: 2

PostPosted: Wed Mar 17, 2004 1:56 am    Post subject: Reply with quote

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


Joined: 25 Nov 2003
Posts: 24

PostPosted: Mon May 24, 2004 9:34 pm    Post subject: Reply with quote

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
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 -> Tips and Tricks 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