Skip to content

Commit 4058e6f

Browse files
committed
Add failing spec for issue #514
1 parent 10ae8dc commit 4058e6f

File tree

1 file changed

+33
-19
lines changed

1 file changed

+33
-19
lines changed

spec/examples/daily_rule_spec.rb

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,44 +31,44 @@ module IceCube
3131
schedule = Schedule.new(Time.local(2013, 3, 9, 2, 30, 0))
3232
schedule.add_recurrence_rule Rule.daily
3333
expect(schedule.first(3)).to eq([
34-
Time.local(2013, 3, 9, 2, 30, 0), # -0800
35-
Time.local(2013, 3, 10, 3, 30, 0), # -0700
36-
Time.local(2013, 3, 11, 2, 30, 0) # -0700
37-
])
34+
Time.local(2013, 3, 9, 2, 30, 0), # -0800
35+
Time.local(2013, 3, 10, 3, 30, 0), # -0700
36+
Time.local(2013, 3, 11, 2, 30, 0) # -0700
37+
])
3838
end
3939

4040
it "should not skip times in DST end hour" do
4141
schedule = Schedule.new(Time.local(2013, 11, 2, 2, 30, 0))
4242
schedule.add_recurrence_rule Rule.daily
4343
expect(schedule.first(3)).to eq([
44-
Time.local(2013, 11, 2, 2, 30, 0), # -0700
45-
Time.local(2013, 11, 3, 2, 30, 0), # -0800
46-
Time.local(2013, 11, 4, 2, 30, 0) # -0800
47-
])
44+
Time.local(2013, 11, 2, 2, 30, 0), # -0700
45+
Time.local(2013, 11, 3, 2, 30, 0), # -0800
46+
Time.local(2013, 11, 4, 2, 30, 0) # -0800
47+
])
4848
end
4949

5050
it "should include nearest time to DST start when locking hour_of_day" do
5151
schedule = Schedule.new(Time.local(2013, 3, 9, 2, 0, 0))
5252
schedule.add_recurrence_rule Rule.daily.hour_of_day(2)
5353
expect(schedule.first(3)).to eq([
54-
Time.local(2013, 3, 9, 2, 0, 0), # -0800
55-
Time.local(2013, 3, 10, 3, 0, 0), # -0700
56-
Time.local(2013, 3, 11, 2, 0, 0) # -0700
57-
])
54+
Time.local(2013, 3, 9, 2, 0, 0), # -0800
55+
Time.local(2013, 3, 10, 3, 0, 0), # -0700
56+
Time.local(2013, 3, 11, 2, 0, 0) # -0700
57+
])
5858
end
5959

6060
it "should not skip days where DST changes" do
6161
start_time = Time.local(2013, 3, 10, 0, 0, 0)
62-
schedule = Schedule.new(start_time)
62+
schedule = Schedule.new(start_time)
6363
schedule.add_recurrence_rule Rule.daily.hour_of_day(19)
6464
expect(schedule.occurrences_between(start_time, start_time + ONE_DAY)).to eq([
65-
Time.local(2013, 3, 10, 19, 0, 0)
66-
])
65+
Time.local(2013, 3, 10, 19, 0, 0)
66+
])
6767
end
6868
end
6969

7070
it "should update previous interval" do
71-
t0 = Time.now
71+
t0 = Time.now
7272
rule = Rule.daily(7)
7373
rule.interval(5)
7474
expect(rule.next_time(t0 + 1, t0, nil)).to eq(t0 + 5 * ONE_DAY)
@@ -107,9 +107,23 @@ module IceCube
107107
# check assumption 2 -- 1 (2) (3) (4) 5 (6)
108108
times = schedule.occurrences(t0 + 5 * ONE_DAY)
109109
expect(times).to eq([
110-
t0 + 5 * ONE_HOUR + 45 * ONE_MINUTE,
111-
t0 + 4 * ONE_DAY + 5 * ONE_HOUR + 45 * ONE_MINUTE
112-
])
110+
t0 + 5 * ONE_HOUR + 45 * ONE_MINUTE,
111+
t0 + 4 * ONE_DAY + 5 * ONE_HOUR + 45 * ONE_MINUTE
112+
])
113+
end
114+
115+
it "selects the first possible starting occurrence before starting interval" do
116+
schedule_start = Time.new(2021, 3, 28, 10, 0, 0, 'UTC')
117+
end_time = Time.new(2021, 4, 7, 23, 59, 59, 'UTC')
118+
rule = IceCube::Rule.daily(4).hour_of_day(9).minute_of_hour(0).second_of_minute(0)
119+
schedule = IceCube::Schedule.new(schedule_start) { |s| s.add_recurrence_rule(rule) }
120+
121+
expect(schedule.occurrences(end_time))
122+
.to eq([
123+
Time.new(2021, 3, 29, 9, 0, 0, "UTC"),
124+
Time.new(2021, 4, 2, 9, 0, 0, "UTC"),
125+
Time.new(2021, 4, 6, 9, 0, 0, "UTC")
126+
])
113127
end
114128

115129
describe "day validation" do

0 commit comments

Comments
 (0)