private function expirationToDateTime($expires): DateTimeInterface
    {
        if ($expires instanceof DateTimeImmutable) {
            return $expires;
        }

        if ($expires instanceof DateInterval) {
            $expires = (new DateTime)->add($expires);
        } elseif (is_string($expires) || is_int($expires)) {
            $expires = new DateTime(is_numeric($expires) ? '@' . $expires : $expires);
        }

        if (!$expires instanceof DateTimeInterface) {
            throw new InvalidArgumentException(
                'Invalid cookie expiration time. Cannot be converted to DateTimeInterface.'
            );
        }

        return new DateTimeImmutable($expires->format(DateTime::ISO8601), $expires->getTimezone());
    }