public function transform($dateInterval)
    {
        if (null === $dateInterval) {
            return array_intersect_key(
                [
                    'years' => '',
                    'months' => '',
                    'weeks' => '',
                    'days' => '',
                    'hours' => '',
                    'minutes' => '',
                    'seconds' => '',
                    'invert' => false,
                ],
                array_flip($this->fields)
            );
        }
        if (!$dateInterval instanceof \DateInterval) {
            throw new UnexpectedTypeException($dateInterval, '\DateInterval');
        }
        $result = [];
        foreach (self::$availableFields as $field => $char) {
            $result[$field] = $dateInterval->format('%'.($this->pad ? strtoupper($char) : $char));
        }
        if (\in_array('weeks', $this->fields, true)) {
            $result['weeks'] = '0';
            if (isset($result['days']) && (int) $result['days'] >= 7) {
                $result['weeks'] = (string) floor($result['days'] / 7);
                $result['days'] = (string) ($result['days'] % 7);
            }
        }
        $result['invert'] = '-' === $result['invert'];
        $result = array_intersect_key($result, array_flip($this->fields));

        return $result;
    }
public function transform($dateInterval)
    {
        if (null === $dateInterval) {
            return array_intersect_key(
                [
                    'years' => '',
                    'months' => '',
                    'weeks' => '',
                    'days' => '',
                    'hours' => '',
                    'minutes' => '',
                    'seconds' => '',
                    'invert' => false,
                ],
                array_flip($this->fields)
            );
        }
        if (!$dateInterval instanceof \DateInterval) {
            throw new UnexpectedTypeException($dateInterval, '\DateInterval');
        }
        $result = [];
        foreach (self::$availableFields as $field => $char) {
            $result[$field] = $dateInterval->format('%'.($this->pad ? strtoupper($char) : $char));
        }
        if (\in_array('weeks', $this->fields, true)) {
            $result['weeks'] = '0';
            if (isset($result['days']) && (int) $result['days'] >= 7) {
                $result['weeks'] = (string) floor($result['days'] / 7);
                $result['days'] = (string) ($result['days'] % 7);
            }
        }
        $result['invert'] = '-' === $result['invert'];
        $result = array_intersect_key($result, array_flip($this->fields));

        return $result;
    }
public function transform ( $ dateInterval ) { if ( null === $ dateInterval ) { return array_intersect_key ( [ 'years' => '' , 'months' => '' , 'weeks' => '' , 'days' => '' , 'hours' => '' , 'minutes' => '' , 'seconds' => '' , 'invert' => false , ] , array_flip ( $ this -> fields ) ) ; } if ( ! $ dateInterval instanceof \ DateInterval ) { throw new UnexpectedTypeException ( $ dateInterval , '\DateInterval' ) ; } $ result = [ ] ; foreach ( self :: $ availableFields as $ field => $ char ) { $ result [ $ field ] = $ dateInterval -> format ( '%' . ( $ this -> pad ? strtoupper ( $ char ) : $ char ) ) ; } if ( \ in_array ( 'weeks' , $ this -> fields , true ) ) { $ result [ 'weeks' ] = '0' ; if ( isset ( $ result [ 'days' ] ) && ( int ) $ result [ 'days' ] >= 7 ) { $ result [ 'weeks' ] = ( string ) floor ( $ result [ 'days' ] / 7 ) ; $ result [ 'days' ] = ( string ) ( $ result [ 'days' ] % 7 ) ; } } $ result [ 'invert' ] = '-' === $ result [ 'invert' ] ; $ result = array_intersect_key ( $ result , array_flip ( $ this -> fields ) ) ; return $ result ; }
Transforms a normalized date interval into an interval array.

@param \DateInterval $dateInterval Normalized date interval

@return array Interval array

@throws UnexpectedTypeException if the given value is not a \DateInterval instance
Transforms a normalized date interval into an interval array .