|
1 | 1 | require File.dirname(__FILE__) + '/../spec_helper' |
2 | 2 |
|
3 | 3 | module IceCube |
| 4 | + describe WeeklyRule, 'BYSETPOS' do |
| 5 | + it 'should behave correctly' do |
| 6 | + # Weekly on Monday, Wednesday, and Friday with the week starting on Wednesday, the last day of the set |
| 7 | + schedule = IceCube::Schedule.from_ical("RRULE:FREQ=WEEKLY;COUNT=4;WKST=WE;BYDAY=MO,WE,FR;BYSETPOS=-1") |
| 8 | + schedule.start_time = Time.new(2022, 12, 27, 12, 0, 0) |
| 9 | + expect(schedule.occurrences_between(Time.new(2022, 01, 01), Time.new(2024, 01, 01))). |
| 10 | + to eq([ |
| 11 | + Time.new(2023,1,2,12,0,0), |
| 12 | + Time.new(2023,1,9,12,0,0), |
| 13 | + Time.new(2023,1,16,12,0,0), |
| 14 | + Time.new(2023,1,23,12,0,0) |
| 15 | + ]) |
| 16 | + end |
| 17 | + |
| 18 | + it 'should work with intervals' do |
| 19 | + # Every 2 weeks on Monday, Wednesday, and Friday with the week starting on Wednesday, the last day of the set |
| 20 | + schedule = IceCube::Schedule.from_ical("RRULE:FREQ=WEEKLY;COUNT=4;INTERVAL=2;WKST=WE;BYDAY=MO,WE,FR;BYSETPOS=-1") |
| 21 | + schedule.start_time = Time.new(2022, 12, 27, 12, 0, 0) |
| 22 | + expect(schedule.occurrences_between(Time.new(2022, 01, 01), Time.new(2024, 01, 01))). |
| 23 | + to eq([ |
| 24 | + Time.new(2023,1,9,12,0,0), |
| 25 | + Time.new(2023,1,23,12,0,0), |
| 26 | + Time.new(2023,2,6,12,0,0), |
| 27 | + Time.new(2023,2,20,12,0,0) |
| 28 | + ]) |
| 29 | + end |
| 30 | + end |
| 31 | + |
4 | 32 | describe MonthlyRule, 'BYSETPOS' do |
5 | 33 | it 'should behave correctly' do |
6 | 34 | schedule = IceCube::Schedule.from_ical "RRULE:FREQ=MONTHLY;COUNT=4;BYDAY=WE;BYSETPOS=4" |
|
0 commit comments