Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

time.inc.php

Go to the documentation of this file.
00001 <?
00008 class Time
00009 {
00017     public static function formatRelative($startTime, $parens = true)
00018     {
00019         global $me;
00020         
00021         //make our start and end time.
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         //how long?
00053         $elapsed = $endTime - $startTime;
00054 
00055         //how many years?
00056         $years = floor($elapsed / 31556926);
00057         if ($years && !$detail)
00058             return "$years " . Util::pluralize('year', $years);
00059         $elapsed = $elapsed - ($years * 31556926);
00060         
00061         //okay, months?
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         //weeks?
00068         $weeks = floor($elapsed / 604800);
00069         if ($weeks && !$detail)
00070             return "$weeks " . Util::pluralize('week', $weeks);
00071         $elapsed = $elapsed - ($weeks * 604800);
00072 
00073         //how bout days?
00074         $days = floor($elapsed / 86400);
00075         if ($days && !$detail)
00076             return "$days " . Util::pluralize('day', $days);
00077         $elapsed = $elapsed - ($days * 86400);
00078         
00079         //how bout hours?
00080         $hours = floor($elapsed / 3600);
00081         if ($hours && !$detail)
00082             return "$hours " . Util::pluralize('hour', $hours);
00083         $elapsed = $elapsed - ($hours * 3600);
00084         
00085         //how bout minutes?
00086         $minutes = floor($elapsed / 60);
00087         if ($minutes && !$detail)
00088             return "$minutes " . Util::pluralize('minute', $minutes);
00089         $elapsed = $elapsed - ($minutes * 60);
00090 
00091         //finally, seconds...
00092         $seconds = $elapsed;
00093         if (!$detail && $seconds)
00094             return "$seconds " . Util::pluralize('second', $seconds);
00095 
00096         if (!$detail)
00097             return "now";
00098 
00099         //if we havent already returned
00100         return "$years years, $months months, $weeks weeks, $days days, $hours hours, $minutes minutes, and $seconds seconds ";
00101      }
00102 }
00103 ?>

Generated on Fri Oct 27 12:26:40 2006 for BaseJumper by doxygen 1.3.9.1