lib/roxbury/business_calendar.rb in roxbury-0.2.2 vs lib/roxbury/business_calendar.rb in roxbury-0.2.3
- old
+ new
@@ -34,11 +34,14 @@
raise ArgumentError, 'number_of_hours must not be negative' if number_of_hours < 0
to = cast_time(to, :start)
rolling_timestamp = roll_forward(to)
remaining_hours = number_of_hours
- until (bday = business_day(rolling_timestamp)).include?(rolling_timestamp + remaining_hours.hours)
+ loop do
+ bday = business_day(rolling_timestamp)
+ break if bday.include?(rolling_timestamp + remaining_hours.hours)
remaining_hours -= bday.number_of_working_hours(from: rolling_timestamp)
+ break if remaining_hours < 0
rolling_timestamp = next_working_day(rolling_timestamp)
end
rolling_timestamp + remaining_hours.hours
end