Module: RubyUnits::Time::ClassMethods

Included in:
Time
Defined in:
lib/ruby_units/time.rb

Overview

Class methods for [Time] objects

Instance Method Summary collapse

Instance Method Details

#at(*args, **kwargs) ⇒ ::Time

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

Parameters:

Returns:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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) ⇒ ::Time

Examples:

Time.in '5 min'

Parameters:

Returns:



38
39
40
# File 'lib/ruby_units/time.rb', line 38

def in(duration)
  ::Time.now + duration.to_unit
end