Permalink
Browse files

Fix for ValidatedRule issue [#104]

  • Loading branch information...
1 parent 992c3bf commit 2a32fb8955c2305d5fe28fd81111105833da298b @seejohnrun committed Oct 19, 2012
Showing with 45 additions and 3 deletions.
  1. +3 −3 lib/ice_cube/validated_rule.rb
  2. +42 −0 spec/examples/validated_rule_spec.rb
@@ -36,12 +36,12 @@ def next_time(time, schedule, closing_time)
if fwd = res.min
type = vals.first.type # get the jump type
dst_adjust = !vals.first.respond_to?(:dst_adjust?) || vals.first.dst_adjust?
+ dst_adjust = false if time.utc_offset == 0
wrapper = TimeUtil::TimeWrapper.new(time, dst_adjust)
wrapper.add(type, fwd)
wrapper.clear_below(type)
- if wrapper.to_time == time
- wrapper.add(:sec, wrapper.to_time.utc_offset * 2)
- end
+ # Move over DST if blocked
+ wrapper.add(:sec, time.utc_offset) until wrapper.to_time > time
time = wrapper.to_time
end
false
@@ -0,0 +1,42 @@
+require 'active_support/time'
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe IceCube, "::ValidatedRule" do
+ describe "#next_time" do
+ context "monthly" do
+ let(:rule) { IceCube::Rule.monthly }
+ before { rule.reset }
+ it "Should return current day when starting on same day" do
+ first = Time.new(2013, 2, 25, 0, 0, 0)
+ schedule = IceCube::Schedule.new(first)
+ schedule.add_recurrence_rule rule
+ rule.next_time(first, schedule, nil).should == first
+ end
+
+ it "Should return the next month when starting one second in the future" do
+ first = Time.new(2013, 2, 25, 0, 0, 0)
+ schedule = IceCube::Schedule.new(first)
+ schedule.add_recurrence_rule rule
+ rule.next_time(first + 1, schedule, nil).should == Time.new(2013, 3, 25, 0, 0, 0)
+ end
+
+ context "DST edge" do
+ before { Time.zone = "Europe/London" }
+ let(:first) { Time.zone.parse("Sun, 31 Mar 2013 00:00:00 GMT +00:00") }
+ let(:schedule) {
+ sc = IceCube::Schedule.new(first)
+ sc.add_recurrence_rule rule
+ sc
+ }
+
+ it "should not return the same time on a DST edge when starting one second in the future (results in infinite loop [#98])" do
+ rule.next_time(first + 1, schedule, nil).to_s.should_not == first.to_s
+ end
+
+ it "previous failing test with DST edge taken into account" do
+ rule.next_time(first + 1.hour + 1.second, schedule, nil).to_s.should_not == first.to_s
+ end
+ end
+ end
+ end
+end

0 comments on commit 2a32fb8

Please sign in to comment.