The time between the specified range

I have a cron job running on a Rails server. This rake function makes calls / SMSs for subscribers when an event is triggered. Now that this event runs from 10pm to 8am, I want to keep it in line since no one likes to worry in the middle of the night. How to check if the time is between 10:00 - 8:00.

Note. Each user has his own time zone .. What is in my database

thanks

+4
source share
2 answers

Maybe something like ...

def night_time?(t) t.hour > 22 || t.hour < 8 end 

Can be used:

 store_in(queue) if not night_time?(@time) 
+3
source
 # here "-07:00" is example of user timezone offset if Time.now.getlocal("-07:00").hour.between?(8, 22) #then we send else #we don't send end 
+5
source

Source: https://habr.com/ru/post/1401822/


All Articles