3

ice_cubeをいじり始めたところです 毎週のスケジュール (30 分単位) を作成しました

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)

ここで、1 日を除外したいと思います。これにより、その後、この 1 日のすべてのオカレンスが除外されます。

私はもう試した

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.

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

—何か良いアイデアはありますか?

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 に答える