fix time output bug
This commit is contained in:
@@ -23,12 +23,16 @@ class Utils extends Facade
|
||||
|
||||
public static function minutesToTimeParts($minutes): array
|
||||
{
|
||||
return self::secondsToTimeParts(self::minutesToSeconds($minutes));
|
||||
$hours = floor($minutes / 60);
|
||||
$minutes %= 60;
|
||||
|
||||
return ['h' => $hours, 'm' => $minutes];
|
||||
}
|
||||
|
||||
public static function minutesToTimeString($minutes): string
|
||||
{
|
||||
return self::secondsToTimeString(self::minutesToSeconds($minutes));
|
||||
$hm = self::minutesToTimeParts($minutes);
|
||||
return $hm['h']. 'h '. $hm['m'] . 'm';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,8 +42,8 @@ class Utils extends Facade
|
||||
*/
|
||||
public static function secondsToTimeParts($seconds): array
|
||||
{
|
||||
$dtF = new \DateTime('@0');
|
||||
$dtT = new \DateTime("@$seconds");
|
||||
$dtF = new \DateTime('@0', new \DateTimeZone('UTC'));
|
||||
$dtT = new \DateTime("@$seconds", new \DateTimeZone('UTC'));
|
||||
|
||||
$t = $dtF->diff($dtT);
|
||||
|
||||
|
||||
@@ -25,7 +25,8 @@ class UtilsTest extends TestCase
|
||||
$this->assertEquals(['h' => 0, 'm' => 1, 's' => 2], $t);
|
||||
}
|
||||
|
||||
public function testSecondsToTime() {
|
||||
public function testSecondsToTime()
|
||||
{
|
||||
$t = Utils::secondsToTimeString(3600);
|
||||
$this->assertEquals('1h 0m', $t);
|
||||
|
||||
@@ -38,4 +39,16 @@ class UtilsTest extends TestCase
|
||||
$t = Utils::secondsToTimeString(3722, true);
|
||||
$this->assertEquals('1h 2m 2s', $t);
|
||||
}
|
||||
|
||||
public function testMinutesToTime()
|
||||
{
|
||||
$t = Utils::minutesToTimeParts(65);
|
||||
$this->assertEquals(['h' => 1, 'm' => 5], $t);
|
||||
|
||||
$t = Utils::minutesToTimeString(65);
|
||||
$this->assertEquals('1h 5m', $t);
|
||||
|
||||
$t = Utils::minutesToTimeString(43200);
|
||||
$this->assertEquals('720h 0m', $t);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user