2012-04-17 17 views
0

我有一個在Rails服務器上運行的cron作業。當某些事件觸發時,這個耙子任務使用戶/ SMS發送給訂戶。現在,當用戶選擇的免打擾時間之間的此事件觸發時,我想將其存儲在隊列中。如何檢查時間是否在用戶選擇的DND時間之間。如何使用用戶選擇開始時間,TimeZOne,結束時間實現免打擾(DND)

我想答案提Time between specified range

但是,當用戶選擇DND時間爲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. 

回答

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) 
相關問題