|
|
@ -29,10 +29,19 @@ class Duration {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function __toString () {
|
|
|
|
public function __toString () {
|
|
|
|
return $this->getDays()->asRelativeWhole() . ' '
|
|
|
|
return $this->getDays()->asRelativeWhole() . ' '
|
|
|
|
. str_pad($this->getHours()->asRelativeWhole(), mb_strlen($this->getHours()->getUnitMax()), '0', STR_PAD_LEFT) . ':'
|
|
|
|
. self::showUnit($this->getHours()) . ':'
|
|
|
|
. str_pad($this->getMinutes()->asRelativeWhole(), mb_strlen($this->getMinutes()->getUnitMax()), '0', STR_PAD_LEFT) . ':'
|
|
|
|
. self::showUnit($this->getMinutes()) . ':'
|
|
|
|
. str_pad($this->getSeconds()->asRelativeWhole(), mb_strlen($this->getSeconds()->getUnitMax()), '0', STR_PAD_LEFT) . '.'
|
|
|
|
. self::showUnit($this->getSeconds()) . '.'
|
|
|
|
. str_pad($this->getMilliseconds()->asRelativeWhole(), mb_strlen($this->getMilliseconds()->getUnitMax()), '0', STR_PAD_LEFT);
|
|
|
|
. self::showUnit($this->getMilliseconds());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function showUnit (DurationUnit $durationUnit) {
|
|
|
|
|
|
|
|
$max = $durationUnit->getUnitMax();
|
|
|
|
|
|
|
|
$length = mb_strlen($max);
|
|
|
|
|
|
|
|
if (preg_match('/^1[0]*$/', $max)) {
|
|
|
|
|
|
|
|
$length -= 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return str_pad($durationUnit->asRelativeWhole(), $length, '0', STR_PAD_LEFT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Convert duration to user friendly string
|
|
|
|
* Convert duration to user friendly string
|
|
|
|