Skip to content

Commit

Permalink
Don't calculate for days in next month when start day < 28
Browse files Browse the repository at this point in the history
Fixes #171
  • Loading branch information
avit committed May 16, 2013
1 parent eb94dbc commit decd96d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/ice_cube/validations/lock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions spec/examples/validated_rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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") }
Expand Down

0 comments on commit decd96d

Please sign in to comment.