Class: Time

Inherits:
Object show all
Defined in:
lib/mug/time.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.since(t) ⇒ Object

Returns the number of since since t



47
48
49
# File 'lib/mug/time.rb', line 47

def since t
  t.to_now
end

.until(t) ⇒ Object

Returns the number of seconds until t



40
41
42
# File 'lib/mug/time.rb', line 40

def until t
  t.from_now
end

Instance Method Details

#from_nowObject

Returns the number of seconds until the time represented by this Time object.

target = Time.new 2017, 1, 1, 0, 0, 0
sleep target.from_now


27
28
29
30
31
32
33
# File 'lib/mug/time.rb', line 27

def from_now
  #if time.respond_to? :unix_timestamp
  #  to_i - Time.unix_timestamp
  #else
    self - self.class.now
  #end
end

#to_nowObject

Returns the number of seconds since the time represented by this Time object.

start = Time.now
#...
duration = start.to_now


12
13
14
15
16
17
18
# File 'lib/mug/time.rb', line 12

def to_now
  #if Time.respond_to? :unix_timestamp
  #  Time.unix_timestamp - to_i
  #else
    self.class.now - self
  #end
end