src/DateExtension.php
public function duration($value, $units = ['s', 'm', 'h', 'd', 'w', 'y'], $separator = ' ')
    {
        if (!isset($value)) {
            return null;
        }
        
        list($seconds, $minutes, $hours, $days, $weeks, $years) =
            $this->splitDuration($value, count($units) - 1) + array_fill(0, 6, null);
        
        $duration = '';
        if (isset($years) && isset($units[5])) {
            $duration .= $separator . $years . $units[5];
        }
        
        if (isset($weeks) && isset($units[4])) {
            $duration .= $separator . $weeks . $units[4];
        }
        
        if (isset($days) && isset($units[3])) {
            $duration .= $separator . $days . $units[3];
        }
        
        if (isset($hours) && isset($units[2])) {
            $duration .= $separator . $hours . $units[2];
        }
        
        if (isset($minutes) && isset($units[1])) {
            $duration .= $separator . $minutes . $units[1];
        }
        
        if (isset($seconds) && isset($units[0])) {
            $duration .= $separator . $seconds . $units[0];
        }
        
        return trim($duration, $separator);
    }
public function duration($value, $units = ['s', 'm', 'h', 'd', 'w', 'y'], $separator = ' ')
    {
        if (!isset($value)) {
            return null;
        }
        
        list($seconds, $minutes, $hours, $days, $weeks, $years) =
            $this->splitDuration($value, count($units) - 1) + array_fill(0, 6, null);
        
        $duration = '';
        if (isset($years) && isset($units[5])) {
            $duration .= $separator . $years . $units[5];
        }
        
        if (isset($weeks) && isset($units[4])) {
            $duration .= $separator . $weeks . $units[4];
        }
        
        if (isset($days) && isset($units[3])) {
            $duration .= $separator . $days . $units[3];
        }
        
        if (isset($hours) && isset($units[2])) {
            $duration .= $separator . $hours . $units[2];
        }
        
        if (isset($minutes) && isset($units[1])) {
            $duration .= $separator . $minutes . $units[1];
        }
        
        if (isset($seconds) && isset($units[0])) {
            $duration .= $separator . $seconds . $units[0];
        }
        
        return trim($duration, $separator);
    }
public function duration ( $ value , $ units = [ 's' , 'm' , 'h' , 'd' , 'w' , 'y' ] , $ separator = ' ' ) { if ( ! isset ( $ value ) ) { return null ; } list ( $ seconds , $ minutes , $ hours , $ days , $ weeks , $ years ) = $ this -> splitDuration ( $ value , count ( $ units ) - 1 ) + array_fill ( 0 , 6 , null ) ; $ duration = '' ; if ( isset ( $ years ) && isset ( $ units [ 5 ] ) ) { $ duration .= $ separator . $ years . $ units [ 5 ] ; } if ( isset ( $ weeks ) && isset ( $ units [ 4 ] ) ) { $ duration .= $ separator . $ weeks . $ units [ 4 ] ; } if ( isset ( $ days ) && isset ( $ units [ 3 ] ) ) { $ duration .= $ separator . $ days . $ units [ 3 ] ; } if ( isset ( $ hours ) && isset ( $ units [ 2 ] ) ) { $ duration .= $ separator . $ hours . $ units [ 2 ] ; } if ( isset ( $ minutes ) && isset ( $ units [ 1 ] ) ) { $ duration .= $ separator . $ minutes . $ units [ 1 ] ; } if ( isset ( $ seconds ) && isset ( $ units [ 0 ] ) ) { $ duration .= $ separator . $ seconds . $ units [ 0 ] ; } return trim ( $ duration , $ separator ) ; }
Calculate duration from seconds.
One year is seen as exactly 52 weeks.

Use null to skip a unit.

@param int    $value     Time in seconds
@param array  $units     Time units (seconds, minutes, hours, days, weeks, years)
@param string $separator
@return string
Calculate duration from seconds . One year is seen as exactly 52 weeks .