protected function ttlToSeconds($ttl): int
    {
        if (is_null($ttl)) {
            return $this->defaultSeconds;
        }
        if (is_object($ttl)) {
            if ($ttl instanceof \DateInterval) {
                $seconds = $this->dateIntervalToSeconds($ttl);
                if ($seconds < 0) {
                    throw InvalidArgumentException::dateIntervalInPast();
                }
                return $seconds;
            } else {
                throw StrictTypeException::ttlTypeError($ttl);
            }
        }
        if (! $this->strictType) {
            if (is_numeric($ttl)) {
                $ttl = intval($ttl, 10);
            }
        }
        $type = gettype($ttl);
        if (! in_array($type, array('integer', 'string'))) {
            throw StrictTypeException::ttlTypeError($ttl);
        }
        $now = time();
        if (is_int($ttl)) {
            // allow -1 to adjust the cache time +/- up to 15% of default
            if ($ttl === -1) {
                $seconds = $this->defaultSeconds;
                $partial = intval(round(0.15 * $seconds));
                if ($partial >= 900) {
                    $adjust = random_int(0, $partial);
                    $direction = random_int(0, 1);
                    if ($direction === 0) {
                        $seconds = $seconds + $adjust;
                    } else {
                        $seconds = $seconds - $adjust;
                    }
                }
            } else {
                $seconds = $ttl;
            }
            if ($seconds > $now) {
                return ($seconds - $now);
            }
            if ($seconds < 0) {
                throw InvalidArgumentException::negativeTTL($seconds);
            }
            return $seconds;
        }
        // hope it is a date string
        if ($seconds = strtotime($ttl, $now)) {
            if ($seconds > $now) {
                return ($seconds - $now);
            } else {
                throw InvalidArgumentException::dateStringInPast($ttl);
            }
        }
        throw InvalidArgumentException::invalidTTL($ttl);
    }