Permalink
Browse files

Fix daily rule so that occurrences can properly continue on into a ne…

…w year.
  • Loading branch information...
1 parent 3d1c7bf commit 18a7d3b2dad3d48d10ce9ea10a591a58d5cae3bd @benfyvie committed Aug 24, 2011
Showing with 12 additions and 2 deletions.
  1. +2 −2 lib/ice_cube/rules/daily_rule.rb
  2. +10 −0 spec/examples/daily_rule_spec.rb
@@ -5,8 +5,8 @@ class DailyRule < Rule
# TODO repair
# Determine whether this rule occurs on a give date.
def in_interval?(date, start_date)
- #make sure we're in a proper interval
- day_count = date.yday - start_date.yday
+ #make sure we're in a proper interval
+ day_count = date.to_date - start_date.to_date
day_count % @interval == 0
end
@@ -21,6 +21,16 @@
dates.size.should == 3
dates.should == [DAY, DAY + 2 * IceCube::ONE_DAY, DAY + 4 * IceCube::ONE_DAY]
end
+
+ it 'should produce the correct days for @interval = 2 when crossing into a new year' do
+ start_date = Date.parse('2011-12-29').to_time(:utc)
+ schedule = IceCube::Schedule.new(start_date)
+ schedule.add_recurrence_rule IceCube::Rule.daily(2)
+ #check assumption (3) -- (1) 2 (3) 4 (5) 6
+ dates = schedule.occurrences(start_date + 5 * IceCube::ONE_DAY)
+ dates.size.should == 3
+ dates.should == [start_date, start_date + 2 * IceCube::ONE_DAY, start_date + 4 * IceCube::ONE_DAY]
+ end
it 'should produce the correct days for interval of 4 day with hour and minute of day set' do
start_date = DAY

0 comments on commit 18a7d3b

Please sign in to comment.