diff options
author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-02-22 15:15:00 +0000 |
---|---|---|
committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-02-22 15:15:00 +0000 |
commit | 8b75e02e489c4f02d7749f79615187921d8c0fc4 (patch) | |
tree | 5a77f01311540e09602c83f0b1a20c881a6b190e /engine/lib | |
parent | 999909a52579a31ee732857a7c7ea44a8762e206 (diff) | |
download | elgg-8b75e02e489c4f02d7749f79615187921d8c0fc4.tar.gz elgg-8b75e02e489c4f02d7749f79615187921d8c0fc4.tar.bz2 |
Fixes #1531: Correctly implemented dates for friendly times. No more coding while watching the Olympics!
git-svn-id: http://code.elgg.org/elgg/trunk@3965 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib')
-rw-r--r-- | engine/lib/elgglib.php | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 5f3bfc9f9..9b5b34d86 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -1226,39 +1226,48 @@ function page_draw($title, $body, $sidebar = "") { function friendly_time($time) { $diff = time() - ((int) $time); - if ($diff < 60) { - return elgg_echo("friendlytime:justnow"); - } else if ($diff < 3600) { - $diff = round($diff / 60); + $minute = 60; + $hour = $minute * 60; + $day = $hour * 24; + + if ($diff < $minute) { + $friendly_time = elgg_echo("friendlytime:justnow"); + } else if ($diff < $hour) { + $diff = round($diff / $minute); if ($diff == 0) { $diff = 1; } + if ($diff > 1) { $friendly_time = sprintf(elgg_echo("friendlytime:minutes"), $diff); + } else { + $friendly_time = sprintf(elgg_echo("friendlytime:minutes:singular"), $diff); } - $friendly_time = sprintf(elgg_echo("friendlytime:minutes:singular"), $diff); - } else if ($diff < 86400) { - $diff = round($diff / 3600); + } else if ($diff < $day) { + $diff = round($diff / $hour); if ($diff == 0) { $diff = 1; } + if ($diff > 1) { $friendly_time = sprintf(elgg_echo("friendlytime:hours"), $diff); + } else { + $friendly_time = sprintf(elgg_echo("friendlytime:hours:singular"), $diff); } - $friendly_time = sprintf(elgg_echo("friendlytime:hours:singular"), $diff); } else { - $diff = round($diff / 86400); + $diff = round($diff / $day); if ($diff == 0) { $diff = 1; } + if ($diff > 1) { $friendly_time = sprintf(elgg_echo("friendlytime:days"), $diff); + } else { + $friendly_time = sprintf(elgg_echo("friendlytime:days:singular"), $diff); } - - $friendly_time = sprintf(elgg_echo("friendlytime:days:singular"), $diff); } - $timestamp = htmlentities(date(elgg_echo('friendlytime:date_format', $time))); + $timestamp = htmlentities(date(elgg_echo('friendlytime:date_format'), $time)); return "<acronym title=\"$timestamp\">$friendly_time</acronym>"; } |