3

刚开始玩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.

一种解决方案可能看起来像这样,但它有点恶心:

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)
}

——有更好的主意吗?

4

1 回答 1

1

由于似乎没有其他解决方案并且为了结束这个问题,这就是我正在使用的(如上面对原始问题的更新中所述):

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)
}
于 2012-04-03T05:15:37.320 回答