Chat window now opens with no messages inside.
[Assignment-Trapper.git] / time.php
blobd4720497c10c187b30ac9e83f9a6be3d3a021489
1 <?php
3 function humanTiming ($time)
5 $time = time() - $time; // to get the time since that moment
7 $tokens = array (
8 31536000 => 'year',
9 2592000 => 'month',
10 604800 => 'week',
11 86400 => 'day',
12 3600 => 'hour',
13 60 => 'minute',
14 1 => 'second'
17 foreach ($tokens as $unit => $text) {
18 if ($time < $unit) continue;
19 $numberOfUnits = floor($time / $unit);
20 return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
24 function absHumanTiming($time)
26 $out = '';
27 $now_date = date("U", time());
28 $time = strtotime($time);
30 if($now_date < $time) {
31 $time = ($time - $now_date); // number of seconds into the future
32 $time = $now_date - $time; // subtract difference from current time
33 $out .= humanTiming($time)." left";
34 } else if ($now_date > $time) {
35 $out .= humanTiming($time)." ago";
36 } else {
37 $out = "Just Now";
39 return $out;
42 function tab2space($text, $spaces = 4)
44 // Explode the text into an array of single lines
45 $lines = explode("\n", $text);
47 // Loop through each line
48 foreach ($lines as $line)
50 // Break out of the loop when there are no more tabs to replace
51 while (false !== $tab_pos = strpos($line, "\t"))
53 // Break the string apart, insert spaces then concatenate
54 $start = substr($line, 0, $tab_pos);
55 $tab = str_repeat(' ', $spaces - $tab_pos % $spaces);
56 $end = substr($line, $tab_pos + 1);
57 $line = $start . $tab . $end;
59 $result[] = $line;
61 return implode("\n", $result);