duration() public static method

Note that the more than days is currently not supported accurately. E.g. for days and hours set format to: $d:$H
public static duration ( integer | DateInterval $duration, string $format = '%h:%I:%S' ) : string
$duration integer | DateInterval Duration in seconds or as DateInterval object
$format string Defaults to hours, minutes and seconds
return string Time
Exemplo n.º 1
0
 /**
  * TimeTest::testBuildTime()
  *
  * @return void
  */
 public function testDuration()
 {
     $tests = [7440 => '2:04:00', 7220 => '2:00:20', 5400 => '1:30:00', 3660 => '1:01:00'];
     // positive
     foreach ($tests as $was => $expected) {
         $is = $this->Time->duration($was);
         //pr($is);
         $this->assertEquals($expected, $is);
     }
     // M:SS
     $tests = [7440 => '124:00'];
     foreach ($tests as $was => $expected) {
         $is = $this->Time->duration($was, '%i:%S');
         //pr($is);
         $this->assertEquals($expected, $is);
     }
 }