Skip to content

Commit

Permalink
[HOT FIX] fixing infinite loop on daily view (reverting refactoring c…
Browse files Browse the repository at this point in the history
…ode)
  • Loading branch information
Franco Sellitto committed Oct 14, 2014
1 parent 1028a9c commit 1189e39
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions app/models/inventory_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,36 +122,33 @@ def <=>(other)
#######################################################################

def next_open_date(x = Date.today)
find_date x, :next_open
end

def last_open_date(x = Date.today)
find_date x, :last_open
if workday.closed_days.size < 7
while not is_open_on?(x) do
holiday = running_holiday_on(x)
if holiday
x = holiday.end_date.tomorrow
else
x += 1.day
end
end
end
x
end

private

def find_date date, direction
holiday_border, change_date_operation = case direction
when :next_open then [:end_date, :+]
when :last_open then [:start_date, :-]
else raise "Invalid direction" end

def last_open_date(x = Date.today)
if workday.closed_days.size < 7
while not is_open_on?(date) do
holiday = running_holiday_on(date)
while not is_open_on?(x) do
holiday = running_holiday_on(x)
if holiday
date = holiday.send(holiday_border).tomorrow
x = holiday.start_date.yesterday
else
date = date.send(change_date_operation, 1.day)
x -= 1.day
end
end
end
date
x
end

public

def is_open_on?(date)
workday.is_open_on?(date) and running_holiday_on(date).nil?
end
Expand Down

0 comments on commit 1189e39

Please sign in to comment.