gpt4 book ai didi

ruby /ice_cube : Exclude whole day for hourly recurring event

转载 作者:太空宇宙 更新时间:2023-11-03 16:56:54 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com