Class: Mutx::Support::TimeHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/mutx/support/time_helper.rb

Class Method Summary collapse

Class Method Details

.elapsedObject



15
16
17
# File 'lib/mutx/support/time_helper.rb', line 15

def self.elapsed
  self.now_in_seconds - @@start
end

.elapsed_from_last_check_greater_than?(seconds) ⇒ Boolean

Use start class method before using this class method

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
# File 'lib/mutx/support/time_helper.rb', line 20

def self.elapsed_from_last_check_greater_than? seconds
  raise "seconds arg must be a Fixnum" unless seconds.is_a? Fixnum
  if (self.now_in_seconds - @@stamp) > seconds
    @@stamp = self.now_in_seconds
    true
  else
    false
  end
end

.formatted_time_for(timestamp) ⇒ Object



6
7
8
# File 'lib/mutx/support/time_helper.rb', line 6

def self.formatted_time_for timestamp
  Time.at(timestamp).strftime(Mutx::Support::Configuration.formatted_datetime)
end

.nowObject



41
42
43
# File 'lib/mutx/support/time_helper.rb', line 41

def self.now
  Time.now
end

.now_in_secondsObject



37
38
39
# File 'lib/mutx/support/time_helper.rb', line 37

def self.now_in_seconds
  self.now.to_i
end

.startObject



10
11
12
13
# File 'lib/mutx/support/time_helper.rb', line 10

def self.start
  @@start = self.now_in_seconds
  @@stamp = self.now_in_seconds
end

.wait_for(seconds) ⇒ Object



30
31
32
33
34
35
# File 'lib/mutx/support/time_helper.rb', line 30

def self.wait_for seconds
  self.start
  begin
  end until self.elapsed_from_last_check_greater_than? seconds
  seconds
end