【问题标题】:Ruby/ice_cube: Exclude whole day for hourly recurring eventRuby/ice_cube:排除一整天的每小时重复事件
【发布时间】:2011-11-14 12:57:34
【问题描述】:

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

——有更好的想法吗?

【问题讨论】:

    标签: ruby recurring-events ice-cube


    【解决方案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)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-24
      • 1970-01-01
      • 1970-01-01
      • 2018-07-31
      • 2018-05-24
      • 1970-01-01
      • 2014-06-01
      • 1970-01-01
      相关资源
      最近更新 更多