Source for file Timer.class.php

Documentation is available at Timer.class.php

  1. <?php
  2. /**
  3.  * Gumbo Library Framework
  4.  *
  5.  * LICENSE
  6.  * This library is being released under the terms of the New BSD License.  A
  7.  * copy of the license is packaged with the software (LICENSE.txt).  If no
  8.  * copy is found, a copy of the license template can be found at:
  9.  * http://www.opensource.org/licenses/bsd-license.php
  10.  * 
  11.  * @category Gumbo
  12.  * @package Timer
  13.  * @copyright Copyright (c) 2007, iBayou, Michael Luster
  14.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  15.  * @author Michael Luster <mluster79@yahoo.com>
  16.  * @link http://sourceforge.net/projects/phpgumbo
  17.  * @version 0.0.1
  18.  */
  19.  
  20. /**
  21.  * Timer Interface
  22.  * 
  23.  * This is a digital Stopwatch of sorts.  It simply will mark a start time (in
  24.  * microseconds) and a stop time (in mircoseconds).  It will return the difference
  25.  * between the two as a float.  It should also mark Lap times.  These are time
  26.  * stamps (in mircoseconds) marked between the start and stop time.
  27.  * 
  28.  * STAMP
  29.  * This will indicate the actual microtime value record at the particular Lap.  If
  30.  * the value is '0' or 'null', it will return the Start Stamp (or use startTime()).
  31.  * If the value is negative, the Stop Stamp will return (or use stopTime()).
  32.  * 
  33.  * TIME
  34.  * This will indicate the time on the supplied Lap from the previous Lap.  If the
  35.  * value is '0' or 'null, the total Time (from start to stop) will be returned.  If
  36.  * the value is greater than the total number of laps, the difference from the stop
  37.  * time and the last lap will be given.
  38.  *
  39.  * @category Gumbo
  40.  * @package Timer
  41.  * @copyright Copyright (c) 2007, iBayou, Michael Luster
  42.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  43.  * @author Michael Luster <mluster79@yahoo.com>
  44.  * @link http://sourceforge.net/projects/phpgumbo
  45.  * @desc Timer Interface
  46.  * @version 0.0.1
  47.  */
  48.  
  49. interface Gumbo_Interface_Timer {
  50.     
  51.     /** ACTION METHODS **/
  52.     /**
  53.      * Starts the Timer by recording the current time stamp
  54.      * @precondition !isRunning()
  55.      * @postcondition isStarted()
  56.      * @param bool $reset resets timer
  57.      */
  58.     public function start ($reset=false);
  59.     
  60.     /**
  61.      * Saves the Mark (or Lap)
  62.      * @precondition isRunning()
  63.      */
  64.     public function lap ();
  65.     
  66.     /**
  67.      * Stops the Timer by recording the current time stamp
  68.      * @precondition isRunning()
  69.      * @postcondition isStopped()
  70.      */
  71.     public function stop ();
  72.     
  73.     /**
  74.      * Resets the Timer
  75.      * @postcondition !isRunning()
  76.      * @postcondition isStopped()
  77.      */
  78.     public function reset ();
  79.     
  80.     
  81.     
  82.     /** ACCESSOR METHODS **/
  83.     /**
  84.      * Returns the actual microtime value of the given lap (0 => start time)
  85.      * @param int $lap (0 returns start time, if > laps() or -1, returns stop time)
  86.      * @return num 
  87.      */
  88.     public function stamp ($lap=null);
  89.     
  90.     /**
  91.      * Returns the time difference from the given lap to the previous lap
  92.      * 
  93.      * If the parameter is null or 0, it will return the total time from
  94.      * start to stop recorded by the Timer.
  95.      * 
  96.      * @precondition laps() > 2
  97.      * @param int $lap lap number (if > laps(), returns last time)
  98.      * @param int $precision rounds the number to the given precision
  99.      * @return num 
  100.      */
  101.     public function time ($lap=null$precision=null);
  102.     
  103.     /**
  104.      * Returns the average time between Laps
  105.      * @precondition laps() >= 2
  106.      * @param int $precision rounds the number to the given precision
  107.      * @return num 
  108.      */
  109.     public function average ($precision=null);
  110.     
  111.     /**
  112.      * Returns the number of Laps
  113.      * @return int 
  114.      */
  115.     public function laps ();
  116.     
  117.     /**
  118.      * Returns the start time
  119.      * @return num 
  120.      */
  121.     public function startTime ();
  122.     
  123.     /**
  124.      * Returns the stop time
  125.      * @return num 
  126.      */
  127.     public function stopTime ();
  128.     
  129.     /**
  130.      * Returns if the Timer is running (or has been started)
  131.      * @return bool 
  132.      */
  133.     public function isRunning ();
  134.     
  135.     /**
  136.      * Returns if the Timer is stopped
  137.      * @return bool 
  138.      */
  139.     public function isStopped ();
  140.     
  141. }
  142.  
  143. ?>