Convert TTL to seconds from now

@param null|int|DateInterval $ttl
@return int|null
@throws InvalidArgumentException
337685
protected function ttlToSeconds($ttl): ?int
    {
        if (!isset($ttl)) {
            return $this->ttl;
        }

        if ($ttl instanceof DateInterval) {
            $reference = new DateTimeImmutable();
            $endTime = $reference->add($ttl);

            $ttl = $endTime->getTimestamp() - $reference->getTimestamp();
        }

        if (!is_int($ttl)) {
            $type = (is_object($ttl) ? get_class($ttl) . ' ' : '') . gettype($ttl);
            throw new InvalidArgumentException("ttl should be of type int or DateInterval, not $type");
        }

        return isset($this->ttl) ? min($ttl, $this->ttl) : $ttl;
    }
422778
public function waitForDialog($seconds = null)
    {
        $seconds = is_null($seconds) ? static::$waitSeconds : $seconds;

        $this->driver->wait($seconds, 100)->until(
            WebDriverExpectedCondition::alertIsPresent(), "Waited {$seconds} seconds for dialog."
        );

        return $this;
    }
182298
public static function turnDateIntervalToSeconds(DateInterval $dateInterval)
    {
        return $dateInterval->y * 365 * 24 * 3600
            + $dateInterval->m * 30 * 24 * 3600
            + $dateInterval->d * 24 * 3600
            + $dateInterval->h * 3600
            + $dateInterval->i * 60
            + $dateInterval->s;
    }
38705
public function useMinutes($bool = null)
    {
        if (isset($bool)) {

            $this->option_use_minutes = (bool) $bool;
            $this->set_options['use_minutes'] = 'useMinutes';

            return $this;
        }
        else {

            return $this->option_use_minutes;
        }
    }
937966
public function setMultiple($values, $ttl = null)
    {
        return coollect($values)->map(function ($value, $key) use ($ttl) {
            return $this->set($key, $value, $ttl);
        });
    }
989856
public function toSeconds(\DateInterval $interval = null)
    {
        if ((null === $interval) && isset($this)) {
            $interval = $this;
        }

        $seconds = (string) $interval->s;

        if ($interval->i) {
            $seconds = bcadd($seconds, bcmul($interval->i, self::SECONDS_MINUTE));
        }

        if ($interval->h) {
            $seconds = bcadd($seconds, bcmul($interval->h, self::SECONDS_HOUR));
        }

        if ($interval->d) {
            $seconds = bcadd($seconds, bcmul($interval->d, self::SECONDS_DAY));
        }

        if ($interval->m) {
            $seconds = bcadd($seconds, bcmul($interval->m, self::SECONDS_MONTH));
        }

        if ($interval->y) {
            $seconds = bcadd($seconds, bcmul($interval->y, self::SECONDS_YEAR));
        }

        return $seconds;
    }
55382
public function setTtl($ttl)
    {
        if (!is_null($ttl)) {
            if (!is_numeric($ttl) || (intval($ttl) < 1)) {
                throw new \InvalidArgumentException(sprintf('Invalid TTL: %s', $ttl));
            }

            $this->ttl = intval($ttl);
        } else {
            $this->ttl = null;
        }

        return $this;
    }
346682
def ttl(self):
        

        # result is self ts
        result = getattr(self, Annotation.__TS, None)
        # if result is not None
        if result is not None:
            # result is now - result
            now = time()
            result = result - now

        return result
800069
public static function secondsTo($unit, $seconds)
    {
        $method = $unit.'ToSeconds';

        return  (float) $seconds / (float) self::$method();
    }
1061619
public function getElseSet(string $key, int $ttl, callable $callable)
    {
        if ($this->exists($key)) {
            return $this->get($key);
        }

        try {
            $callable_data = call_user_func($callable);
        } catch( Exception $e ) {
            // throw exception
        }

        $this->set($key, $callable_data);
        $this->expireAt($key, time() + $ttl);

        return $this->get($key);
    }
1129202
public function do_gc($ttl)
    {
        /** @var \ManaPHP\DbInterface $db */
        $db = $this->_di->getShared($this->_db);

        $db->query($this->_source)->whereCmp('expired_time', '<=', time())->delete();

        return true;
    }
402694
public function do_gc($ttl)
    {
        $dir = $this->alias->resolve($this->_dir);
        if (is_dir($dir)) {
            $this->_clean($dir);
        }

        return true;
    }
1190644
public function expire($expire)
    {
        if (is_null($expire)) {
            $this->expire = null;
        } elseif (is_numeric($expire) || $expire instanceof DateInterval) {
            $this->expiresAfter($expire);
        } elseif ($expire instanceof DateTimeInterface) {
            $this->expire = $expire;
        } else {
            throw new InvalidArgumentException('not support datetime');
        }

        return $this;
    }
750269
public function getTtl() {

        if ( is_null($this->expiration) ) return null;

        if ( $this->expiration === 0 ) return 0;

        $now = new DateTime("now");

        if ( $now > $this->expiration ) return -1;

        return (int) $now->diff($this->expiration)->format("%r%s");

    }
738442
protected function normalizeTtl(&$ttl)
    {
        if (!is_int($ttl)) {
            $ttl = (float)$ttl;

            // convert to int if possible
            if ($ttl === (float)(int)$ttl) {
                $ttl = (int)$ttl;
            }
        }

        if ($ttl < 0) {
            throw new InvalidArgumentException("TTL can't be negative");
        }
    }
644522
public function toSeconds(\DateInterval $interval = null): string
    {
        if ($interval === null) {
            $interval = $this;
        }

        return static::intervalToSeconds($interval);
    }
615311
public function set($key, $value, $ttl = null)
	{
		return $this->_set($key, $value, $ttl, false);
	}