[ Index ]

PHP Cross Reference of MyBB 1.8.38

title

Body

[close]

/inc/ -> class_timers.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.8
   4   * Copyright 2014 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://www.mybb.com
   7   * License: http://www.mybb.com/about/license
   8   *
   9   */
  10  
  11  class timer {
  12  
  13      /**
  14       * The timer name.
  15       *
  16       * @var string
  17       */
  18      public $name;
  19  
  20      /**
  21       * The start time of this timer.
  22       *
  23       * @var int
  24       */
  25      public $start;
  26  
  27      /**
  28       * The end time of this timer.
  29       *
  30       * @var int
  31       */
  32      public $end;
  33  
  34      /**
  35       * The total time this timer has run.
  36       *
  37       * @var int
  38       */
  39      public $totaltime;
  40  
  41      /**
  42       * The formatted total time this timer has run.
  43       *
  44       * @var string
  45       */
  46      public $formatted;
  47  
  48      /**
  49       * Constructor of class.
  50       *
  51       */
  52  	function __construct()
  53      {
  54          $this->add();
  55      }
  56  
  57      /**
  58       * Starts the timer.
  59       *
  60       */
  61  	function add()
  62      {
  63          if(!$this->start)
  64          {
  65              $this->start = microtime(true);
  66          }
  67      }
  68  
  69      /**
  70       * Gets the time for which the timer has run up until this point.
  71       *
  72       * @return string|boolean The formatted time up until now or false when timer is no longer running.
  73       */
  74  	function getTime()
  75      {
  76          if($this->end) // timer has been stopped
  77          {
  78              return $this->totaltime;
  79          }
  80          elseif($this->start && !$this->end) // timer is still going
  81          {
  82              $currenttime = microtime(true);
  83              $totaltime = $currenttime - $this->start;
  84              return $this->format($totaltime);
  85          }
  86          else
  87          {
  88              return false;
  89          }
  90      }
  91  
  92      /**
  93       * Stops the timer.
  94       *
  95       * @return string The formatted total time.
  96       */
  97  	function stop()
  98      {
  99          if($this->start)
 100          {
 101              $this->end = microtime(true);
 102              $totaltime = $this->end - $this->start;
 103              $this->totaltime = $totaltime;
 104              $this->formatted = $this->format($totaltime);
 105              return $this->formatted;
 106          }
 107          return '';
 108      }
 109  
 110      /**
 111       * Removes the timer.
 112       *
 113       */
 114  	function remove()
 115      {
 116          $this->name = "";
 117          $this->start = "";
 118          $this->end = "";
 119          $this->totaltime = "";
 120          $this->formatted = "";
 121      }
 122  
 123      /**
 124       * Formats the timer time in a pretty way.
 125       *
 126       * @param string $string The time string.
 127       * @return string The formatted time string.
 128       */
 129  	function format($string)
 130      {
 131          return number_format($string, 7);
 132      }
 133  }


2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref