diff --git a/app/Support/Units/Time.php b/app/Support/Units/Time.php new file mode 100644 index 00000000..1857111c --- /dev/null +++ b/app/Support/Units/Time.php @@ -0,0 +1,58 @@ +hours = $hours; + } else { + $this->hours = floor($minutes / 60); + } + + $this->minutes = $minutes % 60; + } + + /** + * Get the total number minutes, adding up the hours + * @return float|int + */ + public function getMinutes() + { + return ($this->hours * 60) + $this->minutes; + } + + /** + * Alias to getMinutes() + * @alias getMinutes() + * @return float|int + */ + public function asInt() + { + return $this->getTotalMinutes(); + } + + /** + * Return a time string + * @return string + */ + public function __toString() + { + return $this->hours . 'h ' . $this->minutes . 'm'; + } +} diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php index c1ed7823..3ffc0836 100644 --- a/tests/UtilsTest.php +++ b/tests/UtilsTest.php @@ -9,6 +9,9 @@ class UtilsTest extends TestCase public function testSecondsToTimeParts() { + $t = new \PhpUnitsOfMeasure\PhysicalQuantity\Time(65, 'm'); + echo $t->toUnit('hours'); + $t = Utils::secondsToTimeParts(3600); $this->assertEquals(['h' => 1, 'm' => 0, 's' => 0], $t);