Module: BeforeAndAfter
- Defined in:
- lib/before_and_after.rb
Constant Summary collapse
- LEFT_SIDE_LATER =
1
- RIGHT_SIDE_LATER =
-1
Instance Method Summary collapse
-
#after?(input_time) ⇒ Boolean
-
input_time
- time to compare.
-
-
#before?(input_time) ⇒ Boolean
-
input_time
- time to compare.
-
-
#within_coming?(time_span) ⇒ Boolean
-
time_span
- time span in seconds.
-
-
#within_last?(time_span) ⇒ Boolean
-
time_span
- time span in seconds.
-
Instance Method Details
#after?(input_time) ⇒ Boolean
-
input_time
- time to compareTime.now.after?(2.hours.ago)
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 compareTime.now.before?(2.hours.from_now)
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 seconds2.minutes.from_now.within_coming?(2.hours)
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 seconds2.minutes.ago.within_last?(2.hours)
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 |