2011-09-10 16 views
2

はちょうど私が(時間半の粒度で)週間スケジュールを得たいくつかのルールでルビー/ ice_cubeは:

schedule = IceCube::Schedule.new(Time.now.change(:min => 30)) 

を作成しましたice_cubeで遊んで開始時間ごとの定期的なイベントのために一日を除外する(さんが言わせて例えば、

IceCube::Rule.weekly.day(:tuesday).hour_of_day(14).minute_of_hour(30) 

または

IceCube::Rule.weekly.day(:wednesday).hour_of_day(10).minute_of_hour(0) 

は今、私はその後、この一日の間、すべての出現を排除する完全な一日を、除外したいと思います。

私は

schedule.add_exception_date [DATE] 

を試みたが、私の例外が正確にイベントを一致させるために持っているようです。

すべてのルールをループし、指定した日付の正確な時刻に例外を作成せずにこれを行う方法はありますか?


更新:

より良い例を作るために:

Weekly schedule: 
    * Every monday at 14:40 
    * Every monday at 15:00 
    * Every thursday at 16:00 
    * Every saturday at 10:00 

Exception date: 
    Tuesday, 13th of September 2011 

=> For the week from Monday 12th to Sunday 18th I'd like to get only the occurrences on Thursday and Saturday. 

一つの解決策は、このようなものを見ることができるが、それは少し不快です:

schedule = IceCube::Schedule.from_yaml([PERSISTED SCHEDULE]) 
occurrences = schedule.occurrences_between([START TIME], [END TIME]) 
exceptions = schedule.exdates.map(&:to_date) 
occurrences.reject {|occurrence| 
    exceptions.include?(occurrence.to_date) 
} 

- 良いアイデアは?

答えて

0

この質問を閉じるためにそこには他の解決策はないように思えるとするので、ここでは(上記で既に元の質問へのアップデートで説明したように)私が使用しているものです:

schedule = IceCube::Schedule.from_yaml([PERSISTED SCHEDULE]) 
occurrences = schedule.occurrences_between([START TIME], [END TIME]) 
exceptions = schedule.exdates.map(&:to_date) 
occurrences.reject {|occurrence| 
    exceptions.include?(occurrence.to_date) 
}