Re: Bug in smarty_modifier_date_format

Danilo Buerger <[email protected]> Wed, 10 Jan 2007 16:59:21 +0100
Newsgroups gmane.comp.php.smarty.devel
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Small errata: it should be smarty_make_timestamp() instead of
smarty_make_time_stamp() of course.

Danilo Buerger schrieb:
> Hello list,
> 
> when using Smarty in a Windows environment (substr(PHP_OS,0,3) == 'WIN')
> and trying to format a MySQL timestamp (0000-00-00 00:00:00) an error
> occurs because the string is passed to strftime() without applying
> smarty_make_time_stamp() to the string first. Another bug occurs when
> using the %R format (which is unknown to Windows, see
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_strftime.2c_.wcsftime.asp)).
> So here is the diff that should fix these problems:
> 
> Index: smarty-2.6.16/plugins/modifier.date_format.php
> ===================================================================
> --- smarty-2.6.16/plugins/modifier.date_format.php      (revision 84)
> +++ smarty-2.6.16/plugins/modifier.date_format.php      (working copy)
> @@ -31,10 +31,10 @@
>  function smarty_modifier_date_format($string, $format="%b %e, %Y",
> $default_date=null)
>  {
>      if (substr(PHP_OS,0,3) == 'WIN') {
> -        $hours = strftime('%I', $string);
> +        $hours = strftime('%I', smarty_make_time_stamp($string));
>          $short_hours = ( $hours < 10 ) ? substr( $hours, -1) : $hours;
> -        $_win_from = array ('%e',  '%T',       '%D',        '%l');
> -        $_win_to   = array ('%#d', '%H:%M:%S', '%m/%d/%y',
> $short_hours);
> +        $_win_from = array ('%e',  '%T',       '%D',        '%l',
>    '%R');
> +        $_win_to   = array ('%#d', '%H:%M:%S', '%m/%d/%y',
> $short_hours, '%H:%M');
>          $format = str_replace($_win_from, $_win_to, $format);
>      }
>      if($string != '') {
> 
> Greets,
> 
> Danilo BÃŒrger
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFpQ1Zrwsg9y2CBIURAg7ZAKCH7AVlvg0qdCEvr/tYvxTovhLR/QCcCH4w
W/0RRo2jf/3mk7DLe2f2y30=
=bru1
-----END PGP SIGNATURE-----

-- 
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php