Commit e26dcc486442f273149c8c8d579d96a725f12a1d

Authored by conradverm
1 parent 2894c358

KTS-2471

"create search2 dashets"
Updated. Refactored period calculations.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7362 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 31 additions and 2 deletions
lib/util/ktutil.inc
... ... @@ -37,14 +37,16 @@ class KTUtil {
37 37 const MIN_IN_SECS = 60;
38 38 const HOUR_IN_SECS = 3600;
39 39 const DAY_IN_SECS = 86400;
  40 + const KB = 1024;
  41 + const MB = 1048576;
  42 + const GB = 1073741824;
40 43  
41   - static function computePeriodToDate($start, $suffix = null, $returnArray=false)
  44 + static function computePeriod($diff, $suffix = null, $returnArray=false)
42 45 {
43 46 if (is_null($suffix))
44 47 {
45 48 $suffix = _kt('ago');
46 49 }
47   - $diff = time() - $start;
48 50  
49 51 $days = floor($diff / KTUtil::DAY_IN_SECS);
50 52 $hours = floor(($diff - $days * KTUtil::DAY_IN_SECS) / KTUtil::HOUR_IN_SECS);
... ... @@ -72,6 +74,33 @@ class KTUtil {
72 74 return $str;
73 75 }
74 76  
  77 + static function computePeriodToDate($start, $suffix = null, $returnArray=false)
  78 + {
  79 + return KTUtil::computePeriodToDate(time() - $start, $suffix, $returnArray);
  80 + }
  81 +
  82 + static function filesizeToString($filesize)
  83 + {
  84 + $filesize = (int) $filesize;
  85 +
  86 + if ($filesize >= KTutil::GB)
  87 + {
  88 + return number_format($filesize / KTutil::GB, 2, '.',',') . _kt('GB');
  89 + }
  90 + elseif ($filesize >= KTutil::MB)
  91 + {
  92 + return number_format($filesize / KTutil::MB, 2, '.',',') . _kt('MB');
  93 + }
  94 + elseif ($filesize >= KTutil::KB)
  95 + {
  96 + return number_format($filesize / KTutil::KB, 2, '.',',') . _kt('KB');
  97 + }
  98 + else
  99 + {
  100 + return $filesize . _kt('b');
  101 + }
  102 + }
  103 +
75 104 function extractGPC () {
76 105 foreach (func_get_args() as $var) {
77 106 if (array_key_exists($var, $_REQUEST)) {
... ...