Ruby Rails Time zone rush hour

Multi tool use
Ruby Rails Time zone rush hour
The last developer is using time in our app like this.
:timestamp_requested => Time.now.utc
I want to check if :timestamp_requested
is between 4:15PM
and 6:00PM
CST.
:timestamp_requested
4:15PM
6:00PM
I saw another post that uses in_time_zone
but not sure how to check for between two times?
in_time_zone
t = foo.start_time
#⇒ 2000-01-01 14:20:00 UTC
t.zone
#⇒ "UTC"
t.in_time_zone("America/Chicago")
#⇒ Sat, 01 Jan 2000 09:20:00 EST -05:00
in_time_zone("Central Time (US & Canada)")
see list of all time zones with
rake time:zones:all
– kiddorails
Jul 3 at 4:52
rake time:zones:all
2 Answers
2
The easiest way to check the time is in the specific range would be to compare hours and minutes:
cst = time.in_time_zone("America/Guatemala") # CST whole year
(16..18).cover?(cst.hour) && cst.min >= 15
Love this code. Thank you! Works like a charm and is precise.
– jdog
2 days ago
You might want to try the use_zone
method
use_zone
Time.use_zone("America/Chicago") { (16..18).cover?(time.hour) && time.min >= 15 }
How does it answer the original question?
– mudasobwa
Jul 3 at 5:10
Your logic can be passed into it, just an alternative
– Seun Adex
Jul 3 at 5:23
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
use
in_time_zone("Central Time (US & Canada)")
for CST/CDT?– kiddorails
Jul 3 at 4:51