Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Change human_time() to support durations in the future, and to allow …

…omission of the "ago"/"from now" suffix
  • Loading branch information...
commit 0298673de9e40e1484baa0d20f33b11e5f9149d1 1 parent ffff19a
@cdhowie authored
Showing with 15 additions and 2 deletions.
  1. +15 −2 htdocs/common.inc.php
View
17 htdocs/common.inc.php
@@ -192,8 +192,15 @@ function get_tempdata($key)
$HUMAN_TIME_POSTFIX = array("second", "minute", "hour", "day", "week", "month", "year");
$HUMAN_TIME_LENGTHS = array(60, 60, 24, 7, 4.3452380952380952380952380952381, 12);
-function human_time($difference)
+function human_time($difference, $suffix = true)
{
+ $future = false;
+
+ if ($difference < 0) {
+ $future = true;
+ $difference = -$difference;
+ }
+
global $HUMAN_TIME_POSTFIX, $HUMAN_TIME_LENGTHS;
for ($i = 0; $difference >= $HUMAN_TIME_LENGTHS[$i]; $i++)
@@ -206,7 +213,13 @@ function human_time($difference)
if ($difference != 1)
$postfix .= "s";
- return "$difference $postfix ago";
+ $str = "$difference $postfix";
+
+ if ($suffix) {
+ $str .= ' ' . ($future ? 'from now' : 'ago');
+ }
+
+ return $str;
}
function format_date($date)
Please sign in to comment.
Something went wrong with that request. Please try again.