ruby /ice_cube : Exclude whole day for hourly recurring event

标签 ruby recurring-events ice-cube

刚开始玩弄 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)
}

——还有更好的想法吗?

最佳答案

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

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

关于 ruby /ice_cube : Exclude whole day for hourly recurring event,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7374715/

相关文章:

ruby-on-rails - ice_cube 和 recurring_select gems 和事件

ruby - 确定 ice_cube 计划

javascript - 单击链接工作时无法在 div 的两种颜色之间切换

ruby-on-rails - 急切加载多态关联的第一条记录

ruby - 将值插入到 YAML 转储的哈希中

ruby - 此修改后的二十一点游戏的最佳获胜策略是什么?

database - 重复事件数据库模型

ruby-on-rails - 重复的数据库条目