我在Rails服务器上运行了一个cron作业。当某些事件触发时,此rake任务会向订阅者发出呼叫/ SMS。现在,当此事件在用户选择的DND时间之间触发时,我想将其存储在队列中。如何检查时间是否在用户选择的DND时间之间。
我尝试在Time between specified range
中回答提及但是当用户选择DND Time为6到9时,它会失败
Note:- 1] Every user has its own timezone.. Which I have in the database
2] Every user can select his/her own DND Time.
答案 0 :(得分:2)
我认为以下方法有效 如果
start_hour = Hour when DND Time Starts
end_hour = Hour when DND Time Ends
current hour = Hour of the current time
然后
if start_hour > end_hour
current hour > start_hour || current hour < end_hour
else
current hour > start_hour && current hour < end_hour
end
OR
start_hour > end_hour ? (current hour > start_hour || current hour < end_hour) :
(current hour > start_hour && current hour < end_hour)