Skip to content

Commit

Permalink
Merge remote branch 'latentflip/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
John Crepezzi committed Aug 2, 2010
2 parents 727dadd + e6c6611 commit 42c0a2c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
11 changes: 9 additions & 2 deletions lib/ice_cube/rules/weekly_rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ class WeeklyRule < Rule
def in_interval?(date, start_date)
#make sure we're in the right interval
date = adjust(date, start_date)
week_of_year = Date.civil(date.year, date.month, date.day).cweek
week_of_year % @interval == 0

date = Date.civil(date.year, date.month, date.day)
start_date = Date.civil(start_date.year, start_date.month, start_date.day)

#Move both to the start of their respective weeks,
#and find the number of full weeks between them
no_weeks = ((date - date.wday) - (start_date - start_date.wday)) / 7

no_weeks % @interval == 0
end

def to_ical
Expand Down
14 changes: 12 additions & 2 deletions spec/examples/weekly_rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,19 @@
it 'should produce the correct number of days for @interval = 2 with only one day per week' do
start_date = WEDNESDAY
schedule = Schedule.new(start_date)
schedule.add_recurrence_rule Rule.weekly.day(:thursday)
schedule.add_recurrence_rule Rule.weekly(2).day(:wednesday)
#check assumption
schedule.occurrences(start_date + 7 * 4 * IceCube::ONE_DAY).size.should == 4
dates = schedule.occurrences(start_date + 7*3*IceCube::ONE_DAY)
dates.should == [start_date, start_date + 14*IceCube::ONE_DAY]
end

it 'should produce the correct days for @interval = 2, regardless of the start week' do
start_date = WEDNESDAY + 7*IceCube::ONE_DAY
schedule = Schedule.new(start_date)
schedule.add_recurrence_rule Rule.weekly(2).day(:wednesday)
#check assumption
dates = schedule.occurrences(start_date + 7*3*IceCube::ONE_DAY)
dates.should == [start_date, start_date + 14*IceCube::ONE_DAY]
end

it 'should occurr every 2nd tuesday of a month' do
Expand Down

0 comments on commit 42c0a2c

Please sign in to comment.