public function asDuration($value, $implodeString = ', ', $negativeSign = '-')
    {
        if ($value === null) {
            return $this->nullDisplay;
        }

        if ($value instanceof DateInterval) {
            $isNegative = $value->invert;
            $interval = $value;
        } elseif (is_numeric($value)) {
            $isNegative = $value < 0;
            $zeroDateTime = (new DateTime())->setTimestamp(0);
            $valueDateTime = (new DateTime())->setTimestamp(abs($value));
            $interval = $valueDateTime->diff($zeroDateTime);
        } elseif (strncmp($value, 'P-', 2) === 0) {
            $interval = new DateInterval('P' . substr($value, 2));
            $isNegative = true;
        } else {
            $interval = new DateInterval($value);
            $isNegative = $interval->invert;
        }

        $parts = [];
        if ($interval->y > 0) {
            $parts[] = Yii::t('yii', '{delta, plural, =1{1 year} other{# years}}', ['delta' => $interval->y], $this->locale);
        }
        if ($interval->m > 0) {
            $parts[] = Yii::t('yii', '{delta, plural, =1{1 month} other{# months}}', ['delta' => $interval->m], $this->locale);
        }
        if ($interval->d > 0) {
            $parts[] = Yii::t('yii', '{delta, plural, =1{1 day} other{# days}}', ['delta' => $interval->d], $this->locale);
        }
        if ($interval->h > 0) {
            $parts[] = Yii::t('yii', '{delta, plural, =1{1 hour} other{# hours}}', ['delta' => $interval->h], $this->locale);
        }
        if ($interval->i > 0) {
            $parts[] = Yii::t('yii', '{delta, plural, =1{1 minute} other{# minutes}}', ['delta' => $interval->i], $this->locale);
        }
        if ($interval->s > 0) {
            $parts[] = Yii::t('yii', '{delta, plural, =1{1 second} other{# seconds}}', ['delta' => $interval->s], $this->locale);
        }
        if ($interval->s === 0 && empty($parts)) {
            $parts[] = Yii::t('yii', '{delta, plural, =1{1 second} other{# seconds}}', ['delta' => $interval->s], $this->locale);
            $isNegative = false;
        }

        return empty($parts) ? $this->nullDisplay : (($isNegative ? $negativeSign : '') . implode($implodeString, $parts));
    }
public function asDuration($value, $implodeString = ', ', $negativeSign = '-')
    {
        if ($value === null) {
            return $this->nullDisplay;
        }

        if ($value instanceof DateInterval) {
            $isNegative = $value->invert;
            $interval = $value;
        } elseif (is_numeric($value)) {
            $isNegative = $value < 0;
            $zeroDateTime = (new DateTime())->setTimestamp(0);
            $valueDateTime = (new DateTime())->setTimestamp(abs($value));
            $interval = $valueDateTime->diff($zeroDateTime);
        } elseif (strncmp($value, 'P-', 2) === 0) {
            $interval = new DateInterval('P' . substr($value, 2));
            $isNegative = true;
        } else {
            $interval = new DateInterval($value);
            $isNegative = $interval->invert;
        }

        $parts = [];
        if ($interval->y > 0) {
            $parts[] = Yii::t('yii', '{delta, plural, =1{1 year} other{
        }
        if ($interval->m > 0) {
            $parts[] = Yii::t('yii', '{delta, plural, =1{1 month} other{
        }
        if ($interval->d > 0) {
            $parts[] = Yii::t('yii', '{delta, plural, =1{1 day} other{
        }
        if ($interval->h > 0) {
            $parts[] = Yii::t('yii', '{delta, plural, =1{1 hour} other{
        }
        if ($interval->i > 0) {
            $parts[] = Yii::t('yii', '{delta, plural, =1{1 minute} other{
        }
        if ($interval->s > 0) {
            $parts[] = Yii::t('yii', '{delta, plural, =1{1 second} other{
        }
        if ($interval->s === 0 && empty($parts)) {
            $parts[] = Yii::t('yii', '{delta, plural, =1{1 second} other{
            $isNegative = false;
        }

        return empty($parts) ? $this->nullDisplay : (($isNegative ? $negativeSign : '') . implode($implodeString, $parts));
    }
public function asDuration ( $ value , $ implodeString = ', ' , $ negativeSign = '-' ) { if ( $ value === null ) { return $ this -> nullDisplay ; } if ( $ value instanceof DateInterval ) { $ isNegative = $ value -> invert ; $ interval = $ value ; } elseif ( is_numeric ( $ value ) ) { $ isNegative = $ value < 0 ; $ zeroDateTime = ( new DateTime ( ) ) -> setTimestamp ( 0 ) ; $ valueDateTime = ( new DateTime ( ) ) -> setTimestamp ( abs ( $ value ) ) ; $ interval = $ valueDateTime -> diff ( $ zeroDateTime ) ; } elseif ( strncmp ( $ value , 'P-' , 2 ) === 0 ) { $ interval = new DateInterval ( 'P' . substr ( $ value , 2 ) ) ; $ isNegative = true ; } else { $ interval = new DateInterval ( $ value ) ; $ isNegative = $ interval -> invert ; } $ parts = [ ] ; if ( $ interval -> y > 0 ) { $ parts [ ] = Yii :: t ( 'yii' , '{delta, plural, =1{1 year} other{# years}}' , [ 'delta' => $ interval -> y ] , $ this -> locale ) ; } if ( $ interval -> m > 0 ) { $ parts [ ] = Yii :: t ( 'yii' , '{delta, plural, =1{1 month} other{# months}}' , [ 'delta' => $ interval -> m ] , $ this -> locale ) ; } if ( $ interval -> d > 0 ) { $ parts [ ] = Yii :: t ( 'yii' , '{delta, plural, =1{1 day} other{# days}}' , [ 'delta' => $ interval -> d ] , $ this -> locale ) ; } if ( $ interval -> h > 0 ) { $ parts [ ] = Yii :: t ( 'yii' , '{delta, plural, =1{1 hour} other{# hours}}' , [ 'delta' => $ interval -> h ] , $ this -> locale ) ; } if ( $ interval -> i > 0 ) { $ parts [ ] = Yii :: t ( 'yii' , '{delta, plural, =1{1 minute} other{# minutes}}' , [ 'delta' => $ interval -> i ] , $ this -> locale ) ; } if ( $ interval -> s > 0 ) { $ parts [ ] = Yii :: t ( 'yii' , '{delta, plural, =1{1 second} other{# seconds}}' , [ 'delta' => $ interval -> s ] , $ this -> locale ) ; } if ( $ interval -> s === 0 && empty ( $ parts ) ) { $ parts [ ] = Yii :: t ( 'yii' , '{delta, plural, =1{1 second} other{# seconds}}' , [ 'delta' => $ interval -> s ] , $ this -> locale ) ; $ isNegative = false ; } return empty ( $ parts ) ? $ this -> nullDisplay : ( ( $ isNegative ? $ negativeSign : '' ) . implode ( $ implodeString , $ parts ) ) ; }
Represents the value as duration in human readable format.

@param DateInterval|string|int $value the value to be formatted. Acceptable formats:
- [DateInterval object](https://secure.php.net/manual/ru/class.dateinterval.php)
- integer - number of seconds. For example: value `131` represents `2 minutes, 11 seconds`
- ISO8601 duration format. For example, all of these values represent `1 day, 2 hours, 30 minutes` duration:
`2015-01-01T13:00:00Z/2015-01-02T13:30:00Z` - between two datetime values
`2015-01-01T13:00:00Z/P1D2H30M` - time interval after datetime value
`P1D2H30M/2015-01-02T13:30:00Z` - time interval before datetime value
`P1D2H30M` - simply a date interval
`P-1D2H30M` - a negative date interval (`-1 day, 2 hours, 30 minutes`)

@param string $implodeString will be used to concatenate duration parts. Defaults to `, `.
@param string $negativeSign will be prefixed to the formatted duration, when it is negative. Defaults to `-`.
@return string the formatted duration.
@since 2.0.7
Represents the value as duration in human readable format .