/** * nb_FuzzyDate * donne des dates plus sympas par exemple dans les forums * @return $date formatée sous forme de date plus ou moins floue * @param $date Object * marche bien sur http://www.nota-bene.org/ :) */ function nb_FuzzyDate($date) { if($date!='') { // this is now $now = date("U"); // a day is $oneday = 3600 * 24; // reconstructing a 'clean' date from what's in the database $test_date = preg_match_all(",[0-9]*,",$date,$matches); $Y = $matches[0][0]; $M = $matches[0][2]; $D = $matches[0][4]; $computed = date("U", mktime(0,0,0,$M,$D,$Y) ); // $diff is the number of days between $now and $computed $diff = floor(($now-$computed)/$oneday); // conditionally setting $date if($diff < 1) { // then it's today $date = _T('fuzzy_today'); } else if($diff < 2) { // then it's yesterday $date = _T('fuzzy_yesterday'); } else if($diff < 7) { // then it's last {weekday} $date = _T('fuzzy_last_w' . date("w",$computed) ); } else { // too old: resorting to classical affdate display $date = affdate($date); } } return $date; }