Permalink
Browse files

Merge remote branch 'latentflip/master'

  • Loading branch information...
2 parents 727dadd + e6c6611 commit 42c0a2ce2db2925b98e65c676f72ef14e187cadd John Crepezzi committed Aug 2, 2010
Showing with 21 additions and 4 deletions.
  1. +9 −2 lib/ice_cube/rules/weekly_rule.rb
  2. +12 −2 spec/examples/weekly_rule_spec.rb
@@ -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
@@ -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

0 comments on commit 42c0a2c

Please sign in to comment.