Return the ttl given the number of steps, None if steps is not defined
    or we're otherwise unable to calculate one. If relative_time is defined,
    then return a ttl that is the number of seconds from now that the
    record should be expired.
496797
def ttl(self, steps, relative_time=None):
    '''
    
    '''
    if steps:
      # Approximate the ttl based on number of seconds, since it's
      # "close enough"
      if relative_time:
        rtime = self.to_bucket(relative_time)
        ntime = self.to_bucket(time.time())

        # Convert to number of days
        day_diff = (self.from_bucket(ntime, native=True) - self.from_bucket(rtime, native=True)).days
        # Convert steps to number of days as well
        step_diff = (steps*SIMPLE_TIMES[self._step[0]]) / SIMPLE_TIMES['d']

        # The relative time is beyond our TTL cutoff
        if day_diff > step_diff:
          return 0
        # The relative time is in "recent" past or future
        else:
          return (step_diff - day_diff) * SIMPLE_TIMES['d']
      return steps * SIMPLE_TIMES[ self._step[0] ]

    return None
1285498
def validate_session_ttl(session_timeout_in_seconds: float):
        
        if session_timeout_in_seconds < MIN_LOCK_TIMEOUT_IN_SECONDS \
                or session_timeout_in_seconds > MAX_LOCK_TIMEOUT_IN_SECONDS:
            raise InvalidSessionTtlValueError(
                f"Invalid session timeout: {session_timeout_in_seconds}. If defined, the timeout must be between "
                f"{MIN_LOCK_TIMEOUT_IN_SECONDS} and {MAX_LOCK_TIMEOUT_IN_SECONDS} (inclusive).")
326415
def calculateDelay(self, at, delay):
        
        if at is not None:
            return max((datetime.strptime(at, DATETIME_FORMAT) - datetime.utcnow()).total_seconds(), 0)
        elif delay is not None:
            return delay
        else:
            return 0
980293
def normalize(self, timestamp, steps=0):
    '''
    
    '''
    # So far, the only commonality with RelativeTime
    return self.from_bucket( self.to_bucket(timestamp, steps) )
972767
def get_seconds_until_next_day(now=None):
    
    if now is None:
        now = arrow.utcnow()
    return (now.ceil('day') - now).seconds
571416
protected function getExpiry($expiry, $relativeTimestamp)
    {
        if (!is_int($expiry)) {
            $expiry = strtotime($expiry, $relativeTimestamp);
        }

        return $expiry;
    }
1043513
def timestamp
      return nil if self.version != 1
      gmt_timestamp_100_nanoseconds = 0
      gmt_timestamp_100_nanoseconds +=
        ((self.time_hi_and_version  & 0x0FFF) << 48)
      gmt_timestamp_100_nanoseconds += (self.time_mid << 32)
      gmt_timestamp_100_nanoseconds += self.time_low
      return Time.at(
        (gmt_timestamp_100_nanoseconds - 0x01B21DD213814000) / 10000000.0)
    end
493865
def at_time(self, time, nearest_sample=False):
        
        if nearest_sample:
            time += self.delta_t / 2.0
        return self[int((time-self.start_time)*self.sample_rate)]
711911
def validity_duration(self):
        
        if self._proto.HasField('expireMillis'):
            return timedelta(milliseconds=self._proto.expireMillis)
        return None
1269600
def last_updated(self):
        '''
        '''

        key = self.get_key_from_request()
        max_age = self.get_max_age()

        if max_age == 0:
            return datetime.fromtimestamp(Storage.start_time)

        ttl = self.get_storage().ttl(key)

        if ttl >= 0:
            return datetime.now() - timedelta(
                seconds=(
                    max_age - ttl
                )
            )

        if ttl == -1:
            # Per Redis docs: -1 is no expiry, -2 is does not exists.
            return datetime.fromtimestamp(Storage.start_time)

        # Should never reach here. It means the storage put failed or the item
        # somehow does not exists anymore.
        return datetime.now()
1223539
def T(t, step=30):
    
    if hasattr(t, 'timestamp'):
        timestamp = t.timestamp()
    else:
        # python 2
        if t.tzinfo is None:
            timestamp = time.mktime(t.timetuple())
        else:
            utc_naive  = t.replace(tzinfo=None) - t.utcoffset()
            timestamp = (utc_naive - datetime.datetime(1970, 1, 1)).total_seconds()

    return int(timestamp) // step
480039
def ttl(self):
        """"""
        now = time.time() * 1000
        if self._need_update:
            ttl = 0
        else:
            metadata_age = now - self._last_successful_refresh_ms
            ttl = self.config['metadata_max_age_ms'] - metadata_age

        retry_age = now - self._last_refresh_ms
        next_retry = self.config['retry_backoff_ms'] - retry_age

        return max(ttl, next_retry, 0)
640058
public long getNearestPosition(long recordNumber) {
        if (recordNumber < startingRecordNumber || recordNumber > lastRecordNumber)
            throw new IndexOutOfBoundsException();
        return index.get((int) ((recordNumber - startingRecordNumber) / step));
    }
925282
def relative(self):
        
        if not self.is_valid:
            raise ValueError('invalid FQDN `{0}`'.format(self.fqdn))

        if self.is_valid_absolute:
            return self.fqdn[:-1]

        return self.fqdn
122819
def step(self, step_size: Timedelta=None):
        
        old_step_size = self.clock.step_size
        if step_size is not None:
            if not isinstance(step_size, type(self.clock.step_size)):
                raise ValueError(f"Provided time must be an instance of {type(self.clock.step_size)}")
            self.clock._step_size = step_size
        super().step()
        self.clock._step_size = old_step_size
313863
def _wait(self, duration, steps, commands):
        
        wait = ((duration - self.wait * self.reps * commands) / steps) - \
               (self.wait * self.reps * self._bridge.active)
        return max(0, wait)
375734
def _ttl(self):
        """"""
        return self.hlim if isinstance(self, scapy.layers.inet6.IPv6) else self.ttl