1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| // retourne une date selon un tiemstamp, un modele et le fichier de langue
public function date($timestamp,$model,$lang)
{
// timestamp = la date a formater en base de timestamp unix
// model = le modèle remplace des variables standards par leur valeur
// exemple : pour une date "Mercredi 31 Juillet 2008 à 21:30"
// le modele sera : "{LONG_DAY} {DAY} {LONG_MONTH} {LONG_YEAR} à {HOUR}:{MIN}"
// il est complètement modulable
// lang = le fichier de langue courant
// tableau de base
$transDate = array(
'SEC' => date('s',$timestamp),
'MIN' => date('i',$timestamp),
'HOUR' => date('H',$timestamp),
'DAY' => date('d',$timestamp),
'MONTH' => date('m',$timestamp),
'LONG_YEAR' => date('Y',$timestamp),
'SHORT_YEAR' => date('y',$timestamp),
'LONG_DAY' => $lang['DATE_'.strtoupper(date('l',$timestamp))],
'SHORT_DAY' => substr($lang['DATE_'.strtoupper(date('l',$timestamp))],0,3),
'LONG_MONTH' => $lang['DATE_'.strtoupper(date('F',$timestamp))],
'SHORT_MONTH' => substr($lang['DATE_'.strtoupper(date('F',$timestamp))],0,4),
);
// remplacements dans le modele
$model = str_replace('{SEC}',$transDate['SEC'],$model);
$model = str_replace('{MIN}',$transDate['MIN'],$model);
$model = str_replace('{HOUR}',$transDate['HOUR'],$model);
$model = str_replace('{DAY}',$transDate['DAY'],$model);
$model = str_replace('{MONTH}',$transDate['MONTH'],$model);
$model = str_replace('{LONG_YEAR}',$transDate['LONG_YEAR'],$model);
$model = str_replace('{SHORT_YEAR}',$transDate['SHORT_YEAR'],$model);
$model = str_replace('{LONG_DAY}',$transDate['LONG_DAY'],$model);
$model = str_replace('{SHORT_DAY}',$transDate['SHORT_DAY'],$model);
$model = str_replace('{LONG_MONTH}',$transDate['LONG_MONTH'],$model);
$model = str_replace('{SHORT_MONTH}',$transDate['SHORT_MONTH'],$model);
// retour
return $model;
} |
Partager