Module: BeforeAndAfter

Defined in:
lib/before_and_after.rb

Constant Summary collapse

LEFT_SIDE_LATER =
1
RIGHT_SIDE_LATER =
-1

Instance Method Summary collapse

Instance Method Details

#after?(input_time) ⇒ Boolean

  • input_time - time to compare

    Time.now.after?(2.hours.ago)
    

Returns:

  • (Boolean)


18
19
20
# File 'lib/before_and_after.rb', line 18

def after?(input_time)
  (self.utc <=> input_time.utc) == 1
end

#before?(input_time) ⇒ Boolean

  • input_time - time to compare

    Time.now.before?(2.hours.from_now)
    

Returns:

  • (Boolean)


10
11
12
# File 'lib/before_and_after.rb', line 10

def before?(input_time)
  (self.utc <=> input_time.utc) == -1
end

#within_coming?(time_span) ⇒ Boolean

  • time_span - time span in seconds

    2.minutes.from_now.within_coming?(2.hours)
    

Returns:

  • (Boolean)


35
36
37
38
# File 'lib/before_and_after.rb', line 35

def within_coming?(time_span)
  now = Time.now.utc
  self.utc.between?(now, now +  time_span)
end

#within_last?(time_span) ⇒ Boolean

  • time_span - time span in seconds

    2.minutes.ago.within_last?(2.hours)
    

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/before_and_after.rb', line 26

def within_last?(time_span)
  now = Time.now.utc
  self.utc.between?(now - time_span, now)
end