public static function formatAsISO8601(NativeDateInterval $interval)
    {
        $string = 'P';
        $mult   = $interval->invert ? -1 : 1;
        foreach (['y' => 'Y', 'm' => 'M', 'd' => 'D'] as $key => $char) {
            if (0 !== $interval->{$key}) {
                $string .= sprintf('%d%s', $interval->{$key} * $mult, $char);
            }
        }
        if (0 !== $interval->h || 0 !== $interval->i || 0 !== $interval->s || 0.0 !== $interval->f) {
            $string .= 'T';
            foreach (['h' => 'H', 'i' => 'M'] as $key => $char) {
                if (0 !== $interval->{$key}) {
                    $string .= sprintf('%d%s', $interval->{$key} * $mult, $char);
                }
            }
            if (0 !== $interval->s || 0.0 !== $interval->f) {
                if (0.0 === $interval->f) {
                    $string .= sprintf('%d%s', $interval->s * $mult, 'S');
                } else {
                    $string .= rtrim(sprintf('%.6f', ($interval->s + $interval->f) * $mult), '0');
                    $string .= 'S';
                }
            }
        }

        // prevent returning an empty string
        return 'P' === $string ? 'PT0S' : $string;
    }