From b82ddfb655145a59feee7ce3e7cefa6c6a2c3084 Mon Sep 17 00:00:00 2001 From: mistic100 Date: Fri, 10 Feb 2012 17:02:54 +0000 Subject: feature 2564: small changes in infos list git-svn-id: http://piwigo.org/svn/trunk@13086 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/functions.inc.php | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'include/functions.inc.php') diff --git a/include/functions.inc.php b/include/functions.inc.php index 925e43848..4a4677b8a 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -546,34 +546,37 @@ function time_since($original, $stop = 'minute') $ymdhms[] = $tok; $tok = strtok('- :'); } + + if ($ymdhms[0] < 1970) return false; + if (!isset($ymdhms[3])) $ymdhms[3] = 12; + if (!isset($ymdhms[4])) $ymdhms[4] = 0; + if (!isset($ymdhms[5])) $ymdhms[5] = 0; $original = mktime($ymdhms[3],$ymdhms[4],$ymdhms[5],$ymdhms[1],$ymdhms[2],$ymdhms[0]); } // array of time period chunks $chunks = array( - array(60 * 60 * 24 * 365 , 'year'), - array(60 * 60 * 24 * 30 , 'month'), - array(60 * 60 * 24 * 7, 'week'), - array(60 * 60 * 24 , 'day'), - array(60 * 60 , 'hour'), - array(60 , 'minute'), - array(1 , 'second'), + 'year' => 60 * 60 * 24 * 365, + 'month' => 60 * 60 * 24 * 30, + 'week' => 60 * 60 * 24 * 7, + 'day' => 60 * 60 * 24, + 'hour' => 60 * 60, + 'minute' => 60, + 'second' => 1, ); $today = time(); /* Current unix time */ $since = abs($today - $original); $print = null; - for ($i = 0, $j = count($chunks); $i < $j; $i++) + foreach ($chunks as $name => $seconds) { - $seconds = $chunks[$i][0]; - $name = $chunks[$i][1]; if (($count = floor($since / $seconds)) != 0) { - $print.= ($count == 1) ? '1 '.l10n($name).' ' : $count.' '.l10n($name.'s').' '; + $print.= l10n_dec('%d '.$name, '%d '.$name.'s', $count); $since-= $count*$seconds; } - if ($name == $stop) + if (!empty($print) and $chunks[$name] <= $chunks[$stop]) { break; } -- cgit v1.2.3