Browse Source

extract remove_overlapping_and_empty_periods into a separate method

pull/1007/head
Kat 4 years ago
parent
commit
5e10aba272
  1. 10
      app/helpers/locations_helper.rb

10
app/helpers/locations_helper.rb

@ -48,11 +48,11 @@ module LocationsHelper
sorted_deactivation_periods = location.location_deactivation_periods.sort_by(&:deactivation_date)
sorted_deactivation_periods.each do |deactivation|
periods.find { |x| x.to.nil? }.to = deactivation.deactivation_date
periods.find { |period| period.to.nil? }.to = deactivation.deactivation_date
periods << ActivePeriod.new(deactivation.reactivation_date, nil)
end
periods.select { |period| (period.from != period.to) && (period.to.nil? || (period.from.present? && period.from <= period.to)) }
remove_overlapping_and_empty_periods(periods)
end
def location_availability(location)
@ -65,4 +65,10 @@ module LocationsHelper
end
availability.strip
end
private
def remove_overlapping_and_empty_periods(periods)
periods.select { |period| ((period.to.nil? && period.from.present?) || (period.from.present? && period.from < period.to)) }
end
end

Loading…
Cancel
Save