Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/ice_cube/schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ def remaining_occurrences_enumerator(from = nil, options = {})
enumerate_occurrences(from, nil, options)
end

def occurrences_between_enumerator(begin_time, closing_time, options = {})
enumerate_occurrences(begin_time, closing_time, options)
end

# Occurrences between two times
def occurrences_between(begin_time, closing_time, options = {})
enumerate_occurrences(begin_time, closing_time, options).to_a
Expand Down
13 changes: 13 additions & 0 deletions spec/examples/schedule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,19 @@
end
end

describe :occurrences_between_enumerator do
it do
schedule = IceCube::Schedule.new(Time.new(2021, 1, 1))
schedule.add_recurrence_rule(IceCube::Rule.from_ical("FREQ=MONTHLY;BYMONTHDAY=-1"))

start = Time.new(2022, 1, 1)
finish = start + 365 * IceCube::ONE_DAY
dates = schedule.occurrences_between_enumerator(start, finish).lazy.map(&:to_date).first(2)

expect(dates).to eq [Date.new(2022, 1, 31), Date.new(2022, 2, 28)]
end
end

describe :all_occurrences do
it "has end times for each occurrence" do
schedule = IceCube::Schedule.new(Time.now, duration: IceCube::ONE_HOUR)
Expand Down