1 | Index: includes/utils.php |
---|
2 | =================================================================== |
---|
3 | --- includes/utils.php (revision 11787) |
---|
4 | +++ includes/utils.php (working copy) |
---|
5 | @@ -185,30 +185,34 @@ |
---|
6 | |
---|
7 | /** |
---|
8 | * Convert a unix timestamp into an day/hour/minute string |
---|
9 | + * Values are from Google (1 year in seconds and so on). |
---|
10 | * |
---|
11 | * @param int $length time to convert. |
---|
12 | * |
---|
13 | * @return string Translated hour/minute string. |
---|
14 | /**/ |
---|
15 | function nice_length($length) { |
---|
16 | - $days = intVal($length / (24 * 3600)); |
---|
17 | - $hours = intVal(($length % (24 * 3600)) / 3600); |
---|
18 | - $mins = intVal(($length % 3600) / 60); |
---|
19 | + $years = intVal( $length / 31556926 ); |
---|
20 | + $length = $length - ( $years * 31556926 ); |
---|
21 | + $months = intVal( $length / 2629743 ); |
---|
22 | + $length = $length - ( $months * 2629743 ); |
---|
23 | + $days = intVal( $length / 86400); |
---|
24 | + $length = $length - ( $days * 86400 ); |
---|
25 | + $hours = intVal( $length / 3600 ); |
---|
26 | + $length = $length - ( $hours * 3600 ); |
---|
27 | + $mins = intVal( $length / 60 ); |
---|
28 | + $ret = ''; |
---|
29 | + if ($years > 0) |
---|
30 | + $ret = tn('$1 year', '$1 years', $years); |
---|
31 | + if ($months > 0) |
---|
32 | + $ret .= ' '.tn('$1 month', '$1 months', $months); |
---|
33 | if ($days > 0) |
---|
34 | - $ret = tn('$1 day', '$1 days', $days); |
---|
35 | - else |
---|
36 | - $ret = ''; |
---|
37 | - if ($hours > 0) { |
---|
38 | - if ($ret) |
---|
39 | - $ret .= ' '; |
---|
40 | - $ret .= tn('$1 hr', '$1 hrs', $hours); |
---|
41 | - } |
---|
42 | - if ($mins > 0) { |
---|
43 | - if ($ret) |
---|
44 | - $ret .= ' '; |
---|
45 | - $ret .= tn('$1 min', '$1 mins', $mins); |
---|
46 | - } |
---|
47 | - return $ret; |
---|
48 | + $ret .= ' '.tn('$1 day', '$1 days', $days); |
---|
49 | + if ($hours > 0) |
---|
50 | + $ret .= ' '.tn('$1 hr', '$1 hrs', $hours); |
---|
51 | + if ($mins > 0) |
---|
52 | + $ret .= ' '.tn('$1 min', '$1 mins', $mins); |
---|
53 | + return trim($ret); |
---|
54 | } |
---|