Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check given time is after 3pm or not in Rails?

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
like image 976
Salil Avatar asked Dec 21 '22 11:12

Salil


1 Answers

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

is all you need.

like image 131
Mat Avatar answered Jan 11 '23 01:01

Mat