Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix daily rule occurrences #25

Merged
merged 1 commit into from
Aug 24, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/ice_cube/rules/daily_rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions spec/examples/daily_rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down