@param Serializer   $serializer
@param DateInterval $dateInterval

@return mixed
340516
public static function serialize(Serializer $serializer, DateInterval $dateInterval)
    {
        return array(
            Serializer::CLASS_IDENTIFIER_KEY => \get_class($dateInterval),
            'construct' => array(
                Serializer::SCALAR_TYPE => 'string',
                Serializer::SCALAR_VALUE => \sprintf(
                    'P%sY%sM%sDT%sH%sM%sS',
                    $dateInterval->y,
                    $dateInterval->m,
                    $dateInterval->d,
                    $dateInterval->h,
                    $dateInterval->i,
                    $dateInterval->s
                ),
            ),
            'invert' => array(
                Serializer::SCALAR_TYPE => 'integer',
                Serializer::SCALAR_VALUE => (empty($dateInterval->invert)) ? 0 : 1,
            ),
            'days' => array(
                Serializer::SCALAR_TYPE => \gettype($dateInterval->days),
                Serializer::SCALAR_VALUE => $dateInterval->days,
            ),
        );
    }
703747
public static function instance(DateInterval $di)
    {
        $microseconds = $di->f;
        $instance = new static(static::getDateIntervalSpec($di));
        if ($microseconds) {
            $instance->f = $microseconds;
        }
        $instance->invert = $di->invert;
        foreach (['y', 'm', 'd', 'h', 'i', 's'] as $unit) {
            if ($di->$unit < 0) {
                $instance->$unit *= -1;
            }
        }

        return $instance;
    }
193310
public static function getSecondsByInterval(\DateInterval $dateInterval)
    {
        $dateTime = new DateTime;
        $dateTime->add($dateInterval);
        return $dateTime->getTimestamp() - time();
    }
10621
public static function createFromDateInterval(\DateInterval $interval) {
    if ($interval instanceof DateInterval) return $interval;
    
    $ret = new DateInterval($interval->format('P%yY%mM%dDT%hH%iM%sS'));
    $ret->invert = $interval->invert;
      
    return $ret;
  }
782869
public function normalize($object, $format = null, array $context = [])
    {
        if (!$object instanceof \DateInterval) {
            throw new InvalidArgumentException('The object must be an instance of "\DateInterval".');
        }

        return $object->format($context[self::FORMAT_KEY] ?? $this->defaultContext[self::FORMAT_KEY]);
    }
1229153
public function setExpiresIn(DateInterval $interval)
    {
        $now = new DateTimeImmutable();
        $expire = $now->add($interval);
        $this->setExpiresInSeconds($expire->getTimestamp() - $now->getTimestamp());
        return $this;
    }
1256377
private function parseDateInterval($interval)
    {
        try {
            if (!$this->isInstanceOf($interval, 'DateInterval')) {
                $interval = new StringObject($interval);
                if ($interval->startsWith('P')) {
                    $interval = new \DateInterval($interval);
                } else {
                    $interval = \DateInterval::createFromDateString($interval);
                }
            }
        } catch (\Exception $e) {
            throw new DateTimeObjectException(DateTimeObjectException::MSG_INVALID_DATE_INTERVAL, [$interval]);
        }

        return $interval;
    }
3884
public function setSerializers(array $serializers)
    {
        $this->serializers = [];

        foreach ($serializers as $serializer) {
            if (!($serializer instanceof SerializerInterface)) {
                throw new \Exception('SerializerManager manage only ' . __NAMESPACE__ . '\\SerializerInterface');
            }

            $this->serializers[$serializer->getId()] = $serializer;
        }

        return $this;
    }
870451
public static function createResponseModelTransformer(SerializerInterface $serializer = null)
    {
        $serializer = self::prepareSerializer($serializer);

        return new ResponseModelTransformer($serializer);
    }
501804
protected static function getTypedValue(Serializer $serializer, array $value)
    {
        foreach ($value as &$v) {
            $v = $serializer->unserialize($v);
        }

        return $value;
    }
97379
public function getSerializer(): Serializer
    {
        if ($this->serializer) {
            return $this->serializer;
        }

        return $this->serializer = new Serializer([new ModelNormalizer()], [new JsonEncoder()]);
    }
858352
public static function serialize(Serializer $serializer, SplFixedArray $splFixedArray)
    {
        $toArray = [
            Serializer::CLASS_IDENTIFIER_KEY => get_class($splFixedArray),
            Serializer::CLASS_PARENT_KEY => 'SplFixedArray',
            Serializer::SCALAR_VALUE => [],
        ];
        foreach ($splFixedArray->toArray() as $key => $field) {
            $toArray[Serializer::SCALAR_VALUE][$key] = $serializer->serialize($field);
        }

        return $toArray;
    }
746380
public function expiresAfter($timeInterval)
    {
        if ($timeInterval instanceof DateInterval) {
            $this->expire = (int) DateTime::createFromFormat('U', time())->add($timeInterval)->format('U');
        } elseif (is_numeric($timeInterval)) {
            $this->expire = $timeInterval + time();
        } else {
            throw new InvalidArgumentException('not support datetime');
        }

        return $this;
    }
658391
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;
    }
62485
private function getIntervalUnits(\DateTime $date1, \DateTime $date2, string $intervalFormat)
    {
        $result = 0;
        try {
            $interval = new \DateInterval($intervalFormat);
            $periods  = new \DatePeriod($date1, $interval, $date2);

            $result = max(0, iterator_count($periods) - 1);
        } catch (\Exception $e) {
        }

        return $result;
    }
11686
public function add(/*\DateInterval*/ $interval) : \DateTime /*self invariant*/
    {
        // NB: Argument type hinting (\DateInterval $interval)
        // would provoke E_WARNING when cloning.
        // Catch 22: Specs say that native \DateTime method is type hinted,
        // but warning when cloning says it isn't.

        if ($this->frozen) {
            throw new \RuntimeException(get_class($this) . ' is read-only, frozen.');
        }
        return parent::add($interval);
    }
1025354
private function getObjectSerializer(PropertyTypeExtractorInterface $dataServiceExtractor): Serializer
    {
        // First, we need an encoder that filters out null values.
        $encoders = [new CJsonEncoder()];

        // Attempt normalizing each key in this order, including denormalizing recursively.
        $customFieldsNormalizer = new CustomFieldsNormalizer($this->dataService->getCustomFields());
        $normalizers = [
            new UnixMillisecondNormalizer(),
            new UriNormalizer(),
            $customFieldsNormalizer,
            new ObjectNormalizer(
                null, null, null,
                $dataServiceExtractor
            ),
            new ArrayDenormalizer(),
        ];

        $serializer = new Serializer($normalizers, $encoders);
        $customFieldsNormalizer->setSerializer($serializer);

        return $serializer;
    }