PageRenderTime 50ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Dux/MicroTime.php

https://github.com/zeroem/profile-dux
PHP | 57 lines | 27 code | 9 blank | 21 comment | 0 complexity | 3242f7a9b3117a26f6a7e3f421a3f806 MD5 | raw file
  1. <?php
  2. namespace Dux;
  3. class MicroTime
  4. {
  5. /**
  6. * @var integer
  7. */
  8. private $seconds;
  9. /**
  10. * @var integer
  11. */
  12. private $ms;
  13. /**
  14. * Constructs a object representation of microtime data using either
  15. * the default string format of micro time or seconds and ms offset
  16. *
  17. * @param string|int $seconds either a microtime string or the number of seconds since the Unix Epoch
  18. * @param integer $ms milliseconds offset from $seconds
  19. */
  20. public function __construct($seconds, $ms=0) {
  21. $this->seconds = $seconds;
  22. $this->ms = $ms;
  23. }
  24. public function getSeconds() {
  25. return $this->seconds;
  26. }
  27. public function getMs() {
  28. return $this->ms;
  29. }
  30. static public function fromString($str) {
  31. $parts = explode(" ", $str);
  32. return new MicroTime($parts[1], $parts[0]);
  33. }
  34. /**
  35. * Return a MicroTimeInterval representing the amount of time
  36. * elapsed between two MicroTime Objects
  37. *
  38. * @param \Dux\MicroTime $end
  39. * @param \Dux\MicroTime $start
  40. * @return \Dux\MicroTimeInterval
  41. */
  42. static public function diff(MicroTime $end, MicroTime $start) {
  43. return new MicroTimeInterval(
  44. $end->getSeconds() - $start->getSeconds(),
  45. $end->getMs() - $start->getMs()
  46. );
  47. }
  48. }