histogram: Make histograms crash less
[ninja.git] / application / helpers / time.php
blobe662583bd3d085307f5c0c1087ec3230dcc84915
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
2 /**
3 * Help class for converting seconds to readable string of days, hours etc
4 */
5 class time_Core
7 /**
8 * Convert a given nr of sec to string,
9 * day, hour, minute, second
11 public static function to_string($t=0)
13 $neg = false;
15 # translate the abbreviations
16 # seems weird but I suppose someone will want this anyway
17 $d = _('d'); // day
18 $h = _('h'); // hour
19 $m = _('m'); // minute
20 $s = _('s'); // second
21 $negative = _("negative") . " ";
23 if (!$t) return "0$d 0$h 0$m 0$s";
24 if ($t < 0) {
25 $neg = 1;
26 $t = 0 - $t;
29 $days = $t / 86400;
30 $days = floor($days);
31 $hrs = ($t / 3600) % 24;
32 $mins = ($t / 60) % 60;
33 $secs = $t % 60;
35 $timestring = "";
36 if ($neg) $timestring .= $negative;
37 if ($days) {
38 $timestring .= $days.$d;
39 if ($hrs || $mins || $secs) $timestring .= " ";
41 if ($hrs) {
42 $timestring .= $hrs.$h;
43 if ($mins || $secs) $timestring .= " ";
45 if ($mins) {
46 $timestring .= $mins.$m;
47 if ($secs) $timestring .= " ";
49 if ($secs) $timestring .= $secs.$s;
50 return $timestring;