4

I want easiest or simplest method which returns me boolean value (true/false) depending on the given time is after 3 pm or not irrespective of date.

for ex:-

   def after_three_pm(time)
     //some code here 
   end

   time= Time.now # Tue Jul 26 11:17:27 +0530 2011  THEN
   after_three_pm(time)  # should return false

   time= Time.now # Tue Jul 26 15:17:27 +0530 2011  THEN
   after_three_pm(time)  #  should return true
Nicolas Kaiser
  • 1,628
  • 2
  • 14
  • 26
Salil
  • 46,566
  • 21
  • 122
  • 156

2 Answers2

9
def after_three_pm(time)
  time.hour >= 15
end

is all you need.

Mat
  • 202,337
  • 40
  • 393
  • 406
2

you simply need to use the "time" function:

    Time.now.hour
=> 11

Now you can just evaluate this against the hour you want.

Timothée Bourguignon
  • 2,190
  • 3
  • 23
  • 39