Skip to content

Demonstrate next_occurrences bug. #524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
33 changes: 33 additions & 0 deletions spec/examples/schedule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,39 @@
end
end

it "next_occurrences properly handles DST boundary when using byday", requires_active_support: true do
Time.zone = "London"

# Our schedule start on Sunday, March 20 at 1:15am local time.
# Note: The DST boundary is a week later on March 27; on that day 1:15 am local time does not exist.
start_time = Time.zone.parse('2022-03-20T01:15:00Z') # Sunday @ 1:15 am local time

schedule = IceCube::Schedule.new start_time
schedule.add_recurrence_rule(IceCube::Rule.from_ical('FREQ=WEEKLY;BYDAY=SU'))

from_time = start_time - 1.second
next_occurrences = schedule.next_occurrences(3, from_time)
expect(next_occurrences[0]).to eq(Time.zone.parse('2022-03-20T01:15:00+0000'))
# Below we expect 2:15 am local time, because 1:15 am local time does not exist
expect(next_occurrences[1]).to eq(Time.zone.parse('2022-03-27T02:15:00+0100'))
# Now it reverts back to 1:15 am local time, as expected
expect(next_occurrences[2]).to eq(Time.zone.parse('2022-04-03T01:15:00+0100'))

from_time = Time.zone.parse('2022-03-26T23:59:58+0000')
# Below we expect 2:15 am local time, because 1:15 am local time does not exist
next_occurrences = schedule.next_occurrences(3, from_time)
expect(next_occurrences[0]).to eq(Time.zone.parse('2022-03-27T02:15:00+0100'))
# Now it reverts back to 1:15 am local time, as expected
expect(next_occurrences[1]).to eq(Time.zone.parse('2022-04-03T01:15:00+0100'))

from_time = Time.zone.parse('2022-03-26T23:59:59+0000')
# Below we expect 2:15 am local time, because 1:15 am local time does not exist
next_occurrences = schedule.next_occurrences(3, from_time)
expect(next_occurrences[0]).to eq(Time.zone.parse('2022-03-27T02:15:00+0100'))
# UNEXPECTED FAIL: It does not revert back to 1:15 am local time, as expected
expect(next_occurrences[1]).to eq(Time.zone.parse('2022-04-03T01:15:00+0100'))
end

def compare_time_zone_info(start_time)
schedule = IceCube::Schedule.new(start_time)
schedule.rrule IceCube::Rule.yearly(1)
Expand Down