homogenous date formatting
authorPierre Habouzit (MadCoder <pierre.habouzit@m4x.org>
Thu, 30 Dec 2004 07:41:16 +0000 (07:41 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:27:03 +0000 (23:27 +0200)
* 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

27 files changed:
ChangeLog
plugins/modifier.date_format.php
templates/admin/homonymes.tpl
templates/admin/newsletter.tpl
templates/admin/utilisateurs.tpl
templates/carnet/panel.tpl
templates/emails.tpl
templates/emails/redirect.tpl
templates/evenements.tpl
templates/fiche.tpl
templates/include/form.valid.evts.tpl
templates/include/minifiche.tpl
templates/listes/moderate.tpl
templates/listes/moderate_mail.tpl
templates/logger-view.tpl
templates/login.tpl
templates/marketing/envoidirect.tpl
templates/marketing/ins_confirmees.tpl
templates/motdepassemd5.success.tpl
templates/newsletter/index.tpl
templates/newsletter/show.tpl
templates/skins.tpl
templates/stats/coupure.tpl
templates/table-editor.tpl
templates/tmpPWD.success.tpl
templates/trezo/gere_operations.tpl
templates/trezo/index.tpl

index 39c6221..c811549 100644 (file)
--- 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
index 1f9f06a..fbf95c2 100644 (file)
  *  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);
     }
 }
 
index b29b0fa..4e9bfe5 100644 (file)
@@ -58,7 +58,7 @@
       {$user.forlife}
       {/if}
     </td>
-    <td>{$user.expire|date_format:"%d %b %Y"}</td>
+    <td>{$user.expire|date_format}</td>
     <td>
       <a href="{"fiche.php"|url}?user={$user.forlife}" class='popup2'>fiche</a>
       <a href="utilisateurs.php?login={$user.forlife}">edit</a>
index f4c22ca..dda16b9 100644 (file)
@@ -33,7 +33,7 @@
   </tr>
   {foreach item=nl from=$nl_list}
   <tr class="{cycle values="pair,impair"}">
-    <td>{$nl.date|date_format:"%Y-%m-%d"}</td>
+    <td>{$nl.date|date_format}</td>
     <td>
       <a href="{"admin/newsletter_edit.php"|url}?nid={$nl.id}">{$nl.titre|default:"[no title]"}</a>
     </td>
index bf5da07..8e7e8a0 100644 (file)
@@ -207,7 +207,7 @@ Pour ceci changer ses permissions en 'disabled'.
       <td>
         <input type="radio" name='best' {if $a.best}checked="checked"{/if} value='{$a.alias}' onclick="this.form.submit()" />
         {if $a.for_life}<strong>{$a.alias}</strong>{else}{$a.alias}{/if}
-        {if $a.expire}<span class='erreur'>(expire le {$a.expire|date_format:"%d %b %Y"})</span>{/if}
+        {if $a.expire}<span class='erreur'>(expire le {$a.expire|date_format})</span>{/if}
       </td>
       {if $a.for_life}
       <td>garanti à vie*</td>
@@ -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"}
 <p class="erreur">
-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}
 </p>
 {/if}
 {/foreach}
index 4124a5b..c25da6d 100644 (file)
@@ -61,7 +61,7 @@ Il faut pour cel
       {/if}
     </td>
     <td style="width:25%">
-      {$promo[row].date|date_format:"%d %b. %Y"}
+      {$promo[row].date|date_format}
     </td>
   </tr>
   {/section}
index 07f883d..422ada5 100644 (file)
@@ -36,7 +36,7 @@
           {foreach from=$aliases item=a}
           <input type='radio' {if $a.best}checked="checked"{/if} name='best' value='{$a.alias}' onclick='this.form.submit()' />
           {if $a.a_vie}(*){/if} <strong>{$a.alias}</strong>@{#globals.mail.domain#} et @{#globals.mail.domain2#}
-          {if $a.expire}<span class='erreur'>(expire le {$a.expire|date_format:"%d %b %Y"})</span>{/if}
+          {if $a.expire}<span class='erreur'>(expire le {$a.expire|date_format})</span>{/if}
           <br />
           {/foreach}
         </div>
index d7db5e3..00d39e6 100644 (file)
@@ -59,7 +59,7 @@
     {foreach from=$alias item=a}
     <li>
     <strong>{$a.alias}@{#globals.mail.domain#}</strong>
-    {if $a.expire}<span class='erreur'>(expire le {$a.expire|date_format:"%d %b %Y"})</span>{/if}
+    {if $a.expire}<span class='erreur'>(expire le {$a.expire|date_format})</span>{/if}
     </li>
     {/foreach}
   </ul>
index 55884a1..25cb795 100644 (file)
@@ -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}
 </p>
 
 {if $validation_message}
index 01ccd6e..8cf5d5f 100644 (file)
@@ -52,12 +52,12 @@ function chgMainWinLoc( strPage ) {
       </div>
       <div class='maj'>
         Fiche mise à jour<br />
-        le {$x.date|date_format:"%d %b. %Y"}
+        le {$x.date|date_format}
       </div>
       <div class="contact">
         <div class='email'>
           {if $x.dcd}
-          Décédé{if $x.sexe}e{/if} le {$x.deces|date_format:"%d %B %Y"}
+          Décédé{if $x.sexe}e{/if} le {$x.deces|date_format}
           {elseif !$x.inscrit}
           Le compte de cette personne n'est pas actif (personne non inscrite ou exclue).
           {else}
index 877e22f..85b7217 100644 (file)
@@ -29,7 +29,7 @@
 </tr>
 <tr class="impair">
   <td class="titre">Péremption</td>
-  <td>{$valid->peremption|date_format:"%d %B %Y"}</td>
+  <td>{$valid->peremption|date_format}</td>
 </tr>
 <tr class="impair">
   <td class="titre">Promos</td>
index 6c4f201..20b365d 100644 (file)
@@ -20,7 +20,7 @@
 
 
 {if !$c.inscrit || $c.dcd}<div class='grayed'>{/if}
-<div class="contact" {if $c.inscrit}{min_auth level='cookie'}title="fiche mise à jour le {$c.date|date_format:"%d %b %Y"}"{/min_auth}{/if}>
+<div class="contact" {if $c.inscrit}{min_auth level='cookie'}title="fiche mise à jour le {$c.date|date_format}"{/min_auth}{/if}>
   <div class="nom">
     {if $c.sexe}&bull;{/if}
     {min_auth level="cookie"}
@@ -41,7 +41,7 @@
     {/if}
     (X {$c.promo}{if $c.app0text}, {applis_fmt type=$c.app0type text=$c.app0text url=$c.app0url}
     {/if}{if $c.app1text}, {applis_fmt type=$c.app1type text=$c.app1text url=$c.app1url}{/if})
-    {if $c.dcd}décédé{if $c.sexe}e{/if} le {$c.deces|date_format:"%d %b. %Y"}{/if}
+    {if $c.dcd}décédé{if $c.sexe}e{/if} le {$c.deces|date_format}{/if}
     {min_auth level="cookie"}
     {if !$c.dcd && !$c.wasinscrit}
     <a href="{"marketing/public.php"|url}?num={$c.matricule}" class='popup'>clique ici si tu connais son adresse email !</a>
index 5bc75be..2086d89 100644 (file)
@@ -84,7 +84,7 @@
     <td>{$m.sender}</td>
     <td>{$m.subj|default:"[pas de sujet]"}</td>
     <td class='right'>{$m.size}o</td>
-    <td class='right'>{$m.stamp|date_format:"%H:%M:%S<br />%d %b %Y"}</td>
+    <td class='right'>{$m.stamp|date_format:"%X<br />%x"}</td>
     <td class='action'>
       <a href='?liste={$smarty.request.liste}&amp;mid={$m.id}'>voir</a>
       <a href='?liste={$smarty.request.liste}&amp;mid={$m.id}&amp;mok=1'>accepter</a><br />
index 18de0ef..a75f5c4 100644 (file)
@@ -38,7 +38,7 @@
   </tr>
   <tr>
     <td class='titre'>date</td>
-    <td>{$mail.stamp|date_format:"%H:%M:%S le %d %b %Y"}</td>
+    <td>{$mail.stamp|date_format:"%X le %x"}</td>
   </tr>
 </table>
 
index 6bb43b5..7aa8442 100644 (file)
@@ -54,7 +54,7 @@
 </tr>
 {foreach from=$events item=myevent}
 <tr class="{cycle values="impair,pair"}">
-  <td style="font-size:90%;">{$myevent.stamp|date_format:"%Y-%m-%d %H:%M:%S"}</td>
+  <td style="font-size:90%;">{$myevent.stamp|date_format:"%x %X"}</td>
   <td><strong>{$myevent.text}</strong></td>
   <td>{$myevent.data}</td>
 </tr>
   </tr>
 {foreach from=$sessions item=mysess}
   <tr class="{cycle values="impair,pair"}">
-    <td>{$mysess.start|date_format:"%Y-%m-%d %H:%M:%S"}</td>
+    <td>{$mysess.start|date_format:"%x %X"}</td>
     <td><strong>{$mysess.username}</strong> <span class="smaller">({$mysess.lauth})</span></td>
     <td>
       {foreach from=$mysess.events item=myevent}{$myevent}<br />{/foreach}
index 0fc5819..27c5d37 100644 (file)
 
 <div class="smaller">
   Ta connexion précédente date du
-  <strong>{$smarty.session.lastlogin|date_format:"%x, %T"}</strong>
+  <strong>{$smarty.session.lastlogin|date_format:"%x, %X"}</strong>
   depuis la machine <strong>{$smarty.session.host}</strong>
 </div>
   
 {if $fiche_incitation}
   <p>La dernière mise à jour de ta
   <a href="{"fiche.php"|url}?user={$smarty.session.forlife}" class="popup2">fiche</a>
-  date du {$fiche_incitation|date_format:"%x"}.
+  date du {$fiche_incitation|date_format}.
   Il est possible qu'elle ne soit pas à jour.
   Si tu souhaites la modifier, <a href="profil.php">clique ici !</a>
   </p>
index 4af3db8..c8f152a 100644 (file)
   </tr>
   {foreach from=$recents item=it}
   <tr class="{cycle values="pair,impair"}">
-    <td>{$it.date_envoi|date_format:"%e&nbsp;%b&nbsp;%y"}</td>
+    <td>{$it.date_envoi|date_format}</td>
     <td>{$it.sender|lower|truncate:8:""}</td>
     <td>
       <a href="mailto:{$it.email}" title="{$it.email}">{$it.nom} {$it.prenom}</a>
       (x<a href="promo.php?promo={$it.promo}">{$it.promo}</a>)
     </td>
-    <td>{$it.date_succes|date_format:"%e&nbsp;%b&nbsp;%y"}</td>
+    <td>{$it.date_succes|date_format}</td>
   </tr>
   {/foreach}
 </table>
@@ -59,7 +59,7 @@
   </tr>
   {foreach from=$notsub item=it}
   <tr class="{cycle values="pair,impair"}">
-    <td>{$it.date_envoi|date_format:"%e&nbsp;%b&nbsp;%y"}</td>
+    <td>{$it.date_envoi|date_format}</td>
     <td>{$it.sender|lower|truncate:8:""}</td>
     <td>
       <a href="mailto:{$it.email}" title="{$it.email}">{$it.nom} {$it.prenom}</a>
index 9948fec..b1aa2bf 100644 (file)
@@ -28,7 +28,7 @@
   </tr>
 {foreach item=in from=$ins}
   <tr class="{cycle values="impair,pair"}">
-    <td class="center">{$in.date_ins|date_format:"%d/%m/%Y - %H:%M"}</td>
+    <td class="center">{$in.date_ins|date_format:"%x %X"}</td>
     <td class="center">
       <a href="promo.php?promo={$in.promo}">{$in.promo}</a>
     </td>
index f723871..bec6037 100644 (file)
@@ -24,7 +24,7 @@
 </h1>
 
 <p>
-<strong>Mot de passe enregistré le {$smarty.now|date_format:"%x"}</strong>
+<strong>Mot de passe enregistré le {$smarty.now|date_format}</strong>
 </p>
 <p>
   <strong>Attention!</strong> Il est crypté irréversiblement,
index 6288b03..3a719b9 100644 (file)
@@ -80,7 +80,7 @@ Pour te d
   </tr>
   {foreach item=nl from=$nl_list}
   <tr class="{cycle values="impair,pair"}">
-    <td>{$nl.date|date_format:"%d %b %Y"}</td>
+    <td>{$nl.date|date_format}</td>
     <td>
       <a href="{"newsletter/show.php"|url}?nid={$nl.id}">{$nl.titre}</a>
     </td>
index 1335ef4..b97496a 100644 (file)
@@ -19,7 +19,7 @@
  ***************************************************************************}
 
 <h1>
-  Lettre de Polytechnique.org du {$nl->_date|date_format:"%d %B %Y"}
+  Lettre de Polytechnique.org du {$nl->_date|date_format}
 </h1>
 
 <p>
index 6e2b7ee..a60bff9 100644 (file)
@@ -48,7 +48,7 @@ Pour toute information compl
       </td>
       <td class="skimilieu">
         <strong>{$skin.name}</strong>
-        ajoutée le {$skin.date|date_format:"%x"}<br />
+        ajoutée le {$skin.date|date_format}<br />
         {$skin.comment}
         <br /><br />
         Créée par <strong>{$skin.auteur}</strong>
index 0d1efc7..bd95c0d 100644 (file)
@@ -26,7 +26,7 @@
   </tr>
   <tr class="pair">
     <td class="titre">début</td>
-    <td>{$cp.debut|date_format:"%d/%m/%Y, %Hh%M"}</td>
+    <td>{$cp.debut|date_format:"%x %X"}</td>
   </tr>
   <tr class="pair">
     <td class="titre">durée</td>
@@ -75,7 +75,7 @@
   <tr class="{cycle values="pair,impair"}">
     <td>
       <span class="smaller">
-        {$cp.debut|date_format:"%d/%m/%Y"}
+        {$cp.debut|date_format}
       </span>
     </td>
     <td>
index 51ed0e4..8ee2fc9 100644 (file)
@@ -79,7 +79,7 @@
 {if $myval.sum}
   <td>
   {if $myval.type=="timestamp"}
-  <span class="smaller">{$myarr.$mykey|date_format:"%Y-%m-%d %H:%M:%S"}</span>
+  <span class="smaller">{$myarr.$mykey|date_format:"%x %X"}</span>
   {elseif $myval.type=="set" and $myval.trans}
   {$myval.trans[$myval.value]}
   {elseif $myval.type=="ext"}
         {elseif $myval.type=="ext"}
         {extval table=$table field=$mykey name="$prefix$mykey" vtable=$myval.vtable vjoinid=$myval.vjoinid vfield=$myval.vfield selected=$myval.value}
         {elseif $myval.type=="timestamp"}
-        <input type="text" name="{$prefix}{$mykey}" value="{$myval.value|date_format:"%Y-%m-%d %H:%M:%S"}" />
+        <input type="text" name="{$prefix}{$mykey}" value="{$myval.value|date_format:"%x %X"}" />
         {elseif $myval.type=="password"}
         <input type="password" name="{$prefix}{$mykey}" size="40" />
         {else}
index 4de07a8..99124fa 100644 (file)
@@ -21,7 +21,7 @@
 <h1>Récupération de mot de passe</h1>
 
 <p>
-<strong>Mot de passe enregistré le {$smarty.now|date_format:"%x"}</strong>
+<strong>Mot de passe enregistré le {$smarty.now|date_format}</strong>
 </p>
 <p>
   Cette procédure n'est pas sécurisée. Ton mot de passe est certes crypté, mais le
index 1e70228..a79d67f 100644 (file)
@@ -39,7 +39,7 @@
     <tr>
       <td>Date (DD/MM/YYYY)</td>
       <td><input type="text" name="op_date" size="40"
-        value="{$op_date|date_format:"%d/%m/%Y"}" /></td>
+        value="{$op_date|date_format}" /></td>
     </tr>
     <tr>
       <td>Description libre</td>
 {foreach item=op from=$ops}
   <tr class="{cycle values="pair,impair"}">
     <td>{$op.id}</td>
-    <td>{$op.date|date_format:"%d/%m/%Y"}</td>
+    <td>{$op.date|date_format}</td>
     <td>{$op.label}</td>
     <td class="right">{$op.debit}</td>
     <td class="right">{$op.credit}</td>
index 3975b60..63dd5b3 100644 (file)
@@ -46,7 +46,7 @@
   </tr>
 {foreach item=op from=$ops}
   <tr class="{cycle values="impair,pair"}">
-    <td>{$op.date|date_format:"%d/%m/%Y"}</td>
+    <td>{$op.date|date_format}</td>
     <td>{$op.label}</td>
     <td class="right">{$op.debit}</td>
     <td class="right">{$op.credit}</td>