changeset 1017:438457153ced

Add new utility function stStrAtime().
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 05 Nov 2015 18:51:55 +0200
parents b7ebc845e740
children aff236da33ba
files msitegen.inc.php
diffstat 1 files changed, 26 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/msitegen.inc.php	Thu Nov 05 18:26:40 2015 +0200
+++ b/msitegen.inc.php	Thu Nov 05 18:51:55 2015 +0200
@@ -839,6 +839,32 @@
 }
 
 
+$stStrAtimeData =
+[
+  [ 30*24*60*60, "month"  , "months" ],
+  [  7*24*60*60, "week"   , "weeks" ],
+  [    24*60*60, "day"    , "days" ],
+  [       60*60, "hour"   , "hours" ],
+  [          60, "minute" , "minutes" ],
+];
+
+
+function stStrAtime($val)
+{
+  global $stStrAtimeData;
+
+  $res = [];
+  foreach ($stStrAtimeData as $data)
+  if ($val >= $data[0])
+  {
+    $tmp = $val / $data[0];
+    $val = $val % $data[0];
+    $res[] = $tmp." ".($tmp > 1 ? $data[2] : $data[1]);
+  }
+  return implode(", ", $res);
+}
+
+
 function cmPrintCSSLine($filename, $media = FALSE)
 {
   echo