module GRPC::Core::TimeConsts

TimeConsts is a module from the C extension.

Here it’s re-opened to add a utility func.

Constants

INFINITE_FUTURE
INFINITE_PAST
ZERO

Public Class Methods

from_relative_time(timeish) click to toggle source

Converts a time delta to an absolute deadline.

Assumes timeish is a relative time, and converts its to an absolute, with following exceptions:

  • if timish is one of the TimeConsts.TimeSpec constants the value is

preserved.

  • timish < 0 => TimeConsts.INFINITE_FUTURE

  • timish == 0 => TimeConsts.ZERO

@param timeish [Number|TimeSpec] @return [Number|TimeSpec]

# File src/ruby/lib/grpc/core/time_consts.rb, line 36
def from_relative_time(timeish)
  if timeish.is_a? TimeSpec
    timeish
  elsif timeish.nil?
    TimeConsts::ZERO
  elsif !timeish.is_a? Numeric
    fail(TypeError,
         "Cannot make an absolute deadline from #{timeish.inspect}")
  elsif timeish < 0
    TimeConsts::INFINITE_FUTURE
  elsif timeish.zero?
    TimeConsts::ZERO
  else
    Time.now + timeish
  end
end

Private Instance Methods

from_relative_time(timeish) click to toggle source

Converts a time delta to an absolute deadline.

Assumes timeish is a relative time, and converts its to an absolute, with following exceptions:

  • if timish is one of the TimeConsts.TimeSpec constants the value is

preserved.

  • timish < 0 => TimeConsts.INFINITE_FUTURE

  • timish == 0 => TimeConsts.ZERO

@param timeish [Number|TimeSpec] @return [Number|TimeSpec]

# File src/ruby/lib/grpc/core/time_consts.rb, line 36
def from_relative_time(timeish)
  if timeish.is_a? TimeSpec
    timeish
  elsif timeish.nil?
    TimeConsts::ZERO
  elsif !timeish.is_a? Numeric
    fail(TypeError,
         "Cannot make an absolute deadline from #{timeish.inspect}")
  elsif timeish < 0
    TimeConsts::INFINITE_FUTURE
  elsif timeish.zero?
    TimeConsts::ZERO
  else
    Time.now + timeish
  end
end