diff options
author | Steven Wittens <steven@10.no-reply.drupal.org> | 2001-05-17 18:25:08 +0000 |
---|---|---|
committer | Steven Wittens <steven@10.no-reply.drupal.org> | 2001-05-17 18:25:08 +0000 |
commit | e2f051b3854a72e2c7f1af1506f7c3eed6504891 (patch) | |
tree | 08366f8df54658071cfda87cba027b5a7f4c6825 /includes/common.inc | |
parent | daee55e0ec62894a4d43ef48a7e4f64dc57d4a16 (diff) | |
download | brdo-e2f051b3854a72e2c7f1af1506f7c3eed6504891.tar.gz brdo-e2f051b3854a72e2c7f1af1506f7c3eed6504891.tar.bz2 |
Improved and optimized format_interval()
Diffstat (limited to 'includes/common.inc')
-rw-r--r-- | includes/common.inc | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/includes/common.inc b/includes/common.inc index a83645b54..44a353fbb 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -97,20 +97,13 @@ function format_plural($count, $singular, $plural) { } function format_interval($timestamp) { - if ($timestamp >= 86400) { - $output .= format_plural(floor($timestamp / 86400), "day", "days"); - $timestamp = $timestamp % 86400; - } - if ($timestamp >= 3600) { - $output .= " ". format_plural(floor($timestamp / 3600), "hour", "hours"); - $timestamp = $timestamp % 3600; - } - if ($timestamp >= 60) { - $output .= " ". floor($timestamp / 60) ." min"; - $timestamp = $timestamp % 60; - } - if ($timestamp > 0) { - $output .= " $timestamp sec"; + $units = array("year|years"=>31536000, "week|weeks"=>604800, "day|days"=>86400, "hour|hours"=>3600, "min|min"=>60, "sec|sec"=>1); + foreach ($units as $key=>$value) { + $key=explode("|", $key); + if ($timestamp >= $value) { + $output .= ($output ? " " : "") . format_plural(floor($timestamp / $value), $key[0], $key[1]); + $timestamp %= $value; + } } return ($output) ? $output : "0 sec"; } |