From: Pierre Habouzit (MadCoder Date: Thu, 30 Dec 2004 07:41:16 +0000 (+0000) Subject: homogenous date formatting X-Git-Tag: xorg/old~562 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=298c3a9ff164e9b015d58b626b14610015a94dfc;p=platal.git homogenous date formatting * update date_format modifier to use '%x' by default * update date_format modifier to try to use strtotime + strftime (really quicker) and fallback to PEAR::Date if needed. git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-186 --- diff --git a/ChangeLog b/ChangeLog index 39c6221..c811549 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,7 @@ New : - Drop magic_quote_gpc (DB API takes care of it itself). -MC - Drop cache algorithm (was complex for no gain). -MC - Enhancements wrt COOKIE. -MC + - More homogenous date formating (use %x / %X everywhere). -MC * Contacts : - Brand new PDF of the contact list (using FPDF). -MC diff --git a/plugins/modifier.date_format.php b/plugins/modifier.date_format.php index 1f9f06a..fbf95c2 100644 --- a/plugins/modifier.date_format.php +++ b/plugins/modifier.date_format.php @@ -19,17 +19,18 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ -function smarty_modifier_date_format($string, $format="%d %b %Y", $default_date=null) +function smarty_modifier_date_format($string, $format = '%x', $default_date=null) { - require_once('Date.php'); - if($string != '') { - $date = new Date($string); - return $date->format($format); - } elseif (!empty($default_date)) { - $date = new Date($default_date); - return $date->format($format); + if (empty($format) && empty($default_date)) return; + $f = empty($format) ? $default_date : $format; + $f = str_replace('%X', '%T', str_replace('%x', '%d %B %Y', $f)); + + if ( ($t = strtotime($string)) != -1 ) { + return strftime($f , $t); } else { - return; + require_once('Date.php'); + $date = new Date($string); + return $date->format($f); } } diff --git a/templates/admin/homonymes.tpl b/templates/admin/homonymes.tpl index b29b0fa..4e9bfe5 100644 --- a/templates/admin/homonymes.tpl +++ b/templates/admin/homonymes.tpl @@ -58,7 +58,7 @@ {$user.forlife} {/if} - {$user.expire|date_format:"%d %b %Y"} + {$user.expire|date_format} fiche edit diff --git a/templates/admin/newsletter.tpl b/templates/admin/newsletter.tpl index f4c22ca..dda16b9 100644 --- a/templates/admin/newsletter.tpl +++ b/templates/admin/newsletter.tpl @@ -33,7 +33,7 @@ {foreach item=nl from=$nl_list} - {$nl.date|date_format:"%Y-%m-%d"} + {$nl.date|date_format} {$nl.titre|default:"[no title]"} diff --git a/templates/admin/utilisateurs.tpl b/templates/admin/utilisateurs.tpl index bf5da07..8e7e8a0 100644 --- a/templates/admin/utilisateurs.tpl +++ b/templates/admin/utilisateurs.tpl @@ -207,7 +207,7 @@ Pour ceci changer ses permissions en 'disabled'. {if $a.for_life}{$a.alias}{else}{$a.alias}{/if} - {if $a.expire}(expire le {$a.expire|date_format:"%d %b %Y"}){/if} + {if $a.expire}(expire le {$a.expire|date_format}){/if} {if $a.for_life} garanti à vie* @@ -275,7 +275,7 @@ Pour ceci changer ses permissions en 'disabled'. {foreach from=$emails item=mail} {if $email->panne && $email->panne neq "0000-00-00"}

-Panne pour l'email "{$mail->email}" le {$mail->panne|date_format:"%d %b %Y"} +Panne pour l'email "{$mail->email}" le {$mail->panne|date_format}

{/if} {/foreach} diff --git a/templates/carnet/panel.tpl b/templates/carnet/panel.tpl index 4124a5b..c25da6d 100644 --- a/templates/carnet/panel.tpl +++ b/templates/carnet/panel.tpl @@ -61,7 +61,7 @@ Il faut pour cel {/if} - {$promo[row].date|date_format:"%d %b. %Y"} + {$promo[row].date|date_format} {/section} diff --git a/templates/emails.tpl b/templates/emails.tpl index 07f883d..422ada5 100644 --- a/templates/emails.tpl +++ b/templates/emails.tpl @@ -36,7 +36,7 @@ {foreach from=$aliases item=a} {if $a.a_vie}(*){/if} {$a.alias}@{#globals.mail.domain#} et @{#globals.mail.domain2#} - {if $a.expire}(expire le {$a.expire|date_format:"%d %b %Y"}){/if} + {if $a.expire}(expire le {$a.expire|date_format}){/if}
{/foreach} diff --git a/templates/emails/redirect.tpl b/templates/emails/redirect.tpl index d7db5e3..00d39e6 100644 --- a/templates/emails/redirect.tpl +++ b/templates/emails/redirect.tpl @@ -59,7 +59,7 @@ {foreach from=$alias item=a}
  • {$a.alias}@{#globals.mail.domain#} - {if $a.expire}(expire le {$a.expire|date_format:"%d %b %Y"}){/if} + {if $a.expire}(expire le {$a.expire|date_format}){/if}
  • {/foreach} diff --git a/templates/evenements.tpl b/templates/evenements.tpl index 55884a1..25cb795 100644 --- a/templates/evenements.tpl +++ b/templates/evenements.tpl @@ -46,7 +46,7 @@ des promotions {if $promo_min}X{$promo_min}{/if} {if $promo_max}jusqu' {else} de toutes les promotions {/if} -et sera affiché sur la page d'accueil jusqu'au {$peremption|date_format:"%e %b %Y"} +et sera affiché sur la page d'accueil jusqu'au {$peremption|date_format}

    {if $validation_message} diff --git a/templates/fiche.tpl b/templates/fiche.tpl index 01ccd6e..8cf5d5f 100644 --- a/templates/fiche.tpl +++ b/templates/fiche.tpl @@ -52,12 +52,12 @@ function chgMainWinLoc( strPage ) {
    Fiche mise à jour
    - le {$x.date|date_format:"%d %b. %Y"} + le {$x.date|date_format}