刚刚开始玩ice_cube我已经制定了每周计划(半小时的粒度)
schedule = IceCube::Schedule.new(Time.now.change(:min => 30))
有几条规则(比如20),例如例如
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.
一个解决方案可能看起来像这样,但它有点icky:
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 :(得分: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)
}