src/Date.php
public function timespan($time = null, $timezone = null)
    {
        // Get translator
        $lang = $this->getTranslator();

        // Create Date instance if needed
        if (!$time instanceof static) {
            $time = Date::parse($time, $timezone);
        }

        $units = [
            'y' => 'year',
            'm' => 'month',
            'w' => 'week',
            'd' => 'day',
            'h' => 'hour',
            'i' => 'minute',
            's' => 'second',
        ];

        // Get DateInterval and cast to array
        $interval = (array) $this->diff($time);

        // Get weeks
        $interval['w'] = (int) ($interval['d'] / 7);
        $interval['d'] = $interval['d'] % 7;

        // Get ready to build
        $str = [];

        // Loop all units and build string
        foreach ($units as $k => $unit) {
            if ($interval[$k]) {
                $str[] = $lang->transChoice($unit, $interval[$k], [':count' => $interval[$k]]);
            }
        }

        return implode(', ', $str);
    }
public function timespan($time = null, $timezone = null)
    {
        // Get translator
        $lang = $this->getTranslator();

        // Create Date instance if needed
        if (!$time instanceof static) {
            $time = Date::parse($time, $timezone);
        }

        $units = [
            'y' => 'year',
            'm' => 'month',
            'w' => 'week',
            'd' => 'day',
            'h' => 'hour',
            'i' => 'minute',
            's' => 'second',
        ];

        // Get DateInterval and cast to array
        $interval = (array) $this->diff($time);

        // Get weeks
        $interval['w'] = (int) ($interval['d'] / 7);
        $interval['d'] = $interval['d'] % 7;

        // Get ready to build
        $str = [];

        // Loop all units and build string
        foreach ($units as $k => $unit) {
            if ($interval[$k]) {
                $str[] = $lang->transChoice($unit, $interval[$k], [':count' => $interval[$k]]);
            }
        }

        return implode(', ', $str);
    }
public function timespan ( $ time = null , $ timezone = null ) { // Get translator $ lang = $ this -> getTranslator ( ) ; // Create Date instance if needed if ( ! $ time instanceof static ) { $ time = Date :: parse ( $ time , $ timezone ) ; } $ units = [ 'y' => 'year' , 'm' => 'month' , 'w' => 'week' , 'd' => 'day' , 'h' => 'hour' , 'i' => 'minute' , 's' => 'second' , ] ; // Get DateInterval and cast to array $ interval = ( array ) $ this -> diff ( $ time ) ; // Get weeks $ interval [ 'w' ] = ( int ) ( $ interval [ 'd' ] / 7 ) ; $ interval [ 'd' ] = $ interval [ 'd' ] % 7 ; // Get ready to build $ str = [ ] ; // Loop all units and build string foreach ( $ units as $ k => $ unit ) { if ( $ interval [ $ k ] ) { $ str [ ] = $ lang -> transChoice ( $ unit , $ interval [ $ k ] , [ ':count' => $ interval [ $ k ] ] ) ; } } return implode ( ', ' , $ str ) ; }
Gets the timespan between this date and another date.

@param  Date|int $time
@param  string|DateTimeZone $timezone
@return string
Gets the timespan between this date and another date .