Found many ways to check if the current hour is within an hour range. But how would you check if the current time is before a minute-specific time like 10:27 pm
Current Code (only compares hours, not minutes):
Time.now.getlocal("-05:00").hour.between?(10, 22)
For example our store hours are 9:24am - 10:27pm
and we want to check if it is currently open.
As clearly mentioned in docs:
You can also do standard functions like compare two times.
I think you can do something like this:
require 'time'
close_time = Time.parse "10:27 pm"
#=> 2015-11-23 22:27:00 -0800
current_time = Time.now
#=> 2015-11-23 19:38:06 -0800
current_time < close_time
#=> true # means the store is open
late_time = Time.now + 4*60*60
#=> 2015-11-23 23:39:15 -0800
late_time < close_time
#=> false # means the store is close
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With