module RubyUnits::Time::ClassMethods

Class methods for [Time] objects

Public Instance Methods

at(*args, **kwargs) click to toggle source

Convert a duration to a [::Time] object by considering the duration to be the number of seconds since the epoch

@param [Array<RubyUnits::Unit, Numeric, Symbol, Hash>] args @return [::Time]

Calls superclass method
# File lib/ruby_units/time.rb, line 18
def at(*args, **kwargs)
  case args.first
  when RubyUnits::Unit
    options = args.last.is_a?(Hash) ? args.pop : kwargs
    secondary_unit = args[2] || "microsecond"
    case args[1]
    when Numeric
      super((args.first + RubyUnits::Unit.new(args[1], secondary_unit.to_s)).convert_to("second").scalar, **options)
    else
      super(args.first.convert_to("second").scalar, **options)
    end
  else
    super
  end
end
in(duration) click to toggle source

@example

Time.in '5 min'

@param duration [#to_unit] @return [::Time]

# File lib/ruby_units/time.rb, line 38
def in(duration)
  ::Time.now + duration.to_unit
end