From decd96dfd30346614d0c9365c656776a39be1854 Mon Sep 17 00:00:00 2001 From: Andrew Vit Date: Thu, 16 May 2013 14:09:23 -0700 Subject: [PATCH] Don't calculate for days in next month when start day < 28 Fixes #171 --- lib/ice_cube/validations/lock.rb | 4 ++-- spec/examples/validated_rule_spec.rb | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/ice_cube/validations/lock.rb b/lib/ice_cube/validations/lock.rb index d419e315..4c5ff1ff 100644 --- a/lib/ice_cube/validations/lock.rb +++ b/lib/ice_cube/validations/lock.rb @@ -62,8 +62,8 @@ def validate_day_lock(time, schedule) if value && value > 0 until_next_month = days_in_month + sleeps else - until_next_month = TimeUtil.days_to_next_month(date) + sleeps - until_next_month -= month_overflow + until_next_month = start < 28 ? days_in_month : TimeUtil.days_to_next_month(date) + until_next_month += sleeps - month_overflow end sleeps >= 0 ? sleeps : until_next_month diff --git a/spec/examples/validated_rule_spec.rb b/spec/examples/validated_rule_spec.rb index 9c17187b..dc755ff6 100644 --- a/spec/examples/validated_rule_spec.rb +++ b/spec/examples/validated_rule_spec.rb @@ -21,6 +21,13 @@ rule.next_time(first + 1, schedule, nil).should == Time.new(2013, 3, 25, 0, 0, 0) end + it 'should return the next month near end of longer month [#171]' do + schedule = IceCube::Schedule.new(Date.new 2013, 1, 1) + [27, 28, 29, 30, 31].each do |day| + rule.next_time(Time.new(2013, 1, day), schedule, nil).should == Time.new(2013, 2, 1) + end + 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") }