0

我有一个在 Rails 服务器上运行的 cron 作业。当某些事件触发时,此 rake 任务向订阅者发出呼叫/短信。现在,当此事件在用户选择的免打扰时间之间触发时,我想将其存储在队列中。如何检查时间是否在用户选择的免打扰时间之间。

我尝试在指定范围之间的时间中回答提及

但是当用户选择免打扰时间为 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.
4

1 回答 1

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

或者

start_hour > end_hour ?  (current hour > start_hour || current hour < end_hour) : 
                         (current hour > start_hour && current hour < end_hour)
于 2012-04-17T12:19:43.237 回答