Skip to content

Commit

Permalink
Avoid microseconds when comparing times
Browse files Browse the repository at this point in the history
Fixes #83.
  • Loading branch information
avit committed Dec 21, 2012
1 parent 51d3337 commit 8ba3fdd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/ice_cube/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def next_time(time, schedule, closing_time)
end

def on?(time, schedule)
next_time(time, schedule, time) == time
next_time(time, schedule, time).to_i == time.to_i
end

# Whether this rule requires a full run
Expand Down
2 changes: 1 addition & 1 deletion lib/ice_cube/validated_rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def next_time(time, schedule, closing_time)

until finds_acceptable_time?
# Prevent a non-matching infinite loop
return nil if closing_time && @time > closing_time
return nil if closing_time && @time.to_i > closing_time.to_i
end

# NOTE Uses may be 1 higher than proper here since end_time isn't
Expand Down
8 changes: 5 additions & 3 deletions spec/examples/regression_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,14 @@
end

it 'should not include exception times due to rounding errors [#83]' do
start_time = Time.now # start time with usec
exdate = Time.at (start_time + IceCube::ONE_DAY).to_i # one day in the future, no usec
start_time = Time.new(2012, 12, 21, 21, 12, 21.212121)

schedule = IceCube::Schedule.new start_time
schedule.rrule IceCube::Rule.daily
schedule.first(1)[0].mday.should_not == exdate.mday
schedule.exdate (start_time + IceCube::ONE_DAY).round

schedule.first(2)[0].should == start_time
schedule.first(2)[1].should == (start_time + 2*IceCube::ONE_DAY)
end

it 'should return true if a recurring schedule occurs_between? a time range [#88]' do
Expand Down
9 changes: 9 additions & 0 deletions spec/examples/validated_rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@
rule.next_time(first + 1.hour + 1.second, schedule, nil).to_s.should_not == first.to_s
end
end

end

it 'should match times with usec' do
first_time = Time.new(2012, 12, 21, 12, 21, 12.12121212)
schedule = stub(start_time: first_time)
rule = IceCube::Rule.secondly

rule.next_time(first_time + 1, schedule, nil).should == first_time + 1
end
end
end

0 comments on commit 8ba3fdd

Please sign in to comment.