00001 <?
00008 class Time
00009 {
00017 public static function formatRelative($startTime, $parens = true)
00018 {
00019 global $me;
00020
00021
00022 $endTime = time();
00023 $formatStart = $me->formatDateTime($startTime);
00024 $startTime = strtotime($startTime);
00025
00026 if ($startTime > $endTime)
00027 {
00028 $time = Time::elapsed($endTime, $startTime);
00029 $time = "in " . $time;
00030 }
00031 else
00032 {
00033 $time = Time::elapsed($startTime, $endTime);
00034 $time .= " ago";
00035 }
00036
00037 if ($parens)
00038 return "<acronym class=\"relativeTime\" title=\"$formatStart\">($time)</acronym>";
00039 else
00040 return "<acronym class=\"relativeTime\" title=\"$formatStart\">$time</acronym>";
00041 }
00042
00050 public static function elapsed($startTime, $endTime, $detail = false)
00051 {
00052
00053 $elapsed = $endTime - $startTime;
00054
00055
00056 $years = floor($elapsed / 31556926);
00057 if ($years && !$detail)
00058 return "$years " . Util::pluralize('year', $years);
00059 $elapsed = $elapsed - ($years * 31556926);
00060
00061
00062 $months = floor($elapsed / 2629743.83);
00063 if ($months && !$detail)
00064 return "$months " . Util::pluralize('month', $months);
00065 $elapsed = $elapsed - ($months * 2629743.83);
00066
00067
00068 $weeks = floor($elapsed / 604800);
00069 if ($weeks && !$detail)
00070 return "$weeks " . Util::pluralize('week', $weeks);
00071 $elapsed = $elapsed - ($weeks * 604800);
00072
00073
00074 $days = floor($elapsed / 86400);
00075 if ($days && !$detail)
00076 return "$days " . Util::pluralize('day', $days);
00077 $elapsed = $elapsed - ($days * 86400);
00078
00079
00080 $hours = floor($elapsed / 3600);
00081 if ($hours && !$detail)
00082 return "$hours " . Util::pluralize('hour', $hours);
00083 $elapsed = $elapsed - ($hours * 3600);
00084
00085
00086 $minutes = floor($elapsed / 60);
00087 if ($minutes && !$detail)
00088 return "$minutes " . Util::pluralize('minute', $minutes);
00089 $elapsed = $elapsed - ($minutes * 60);
00090
00091
00092 $seconds = $elapsed;
00093 if (!$detail && $seconds)
00094 return "$seconds " . Util::pluralize('second', $seconds);
00095
00096 if (!$detail)
00097 return "now";
00098
00099
00100 return "$years years, $months months, $weeks weeks, $days days, $hours hours, $minutes minutes, and $seconds seconds ";
00101 }
00102 }
00103 ?>