Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def team_availability(time_used_array)
- # total_time_availability = [['8:30', '9:00'],['9:00', '9:30'],['9:30', '10:00'],['10:00', '10:30'],['10:30', '11:00'],['11:00', '11:30'],['11:30', '12:00'],['1:00', '1:30'],['1:30', '2:00'],['2:00', '2:30'],['2:30', '3:00'],['3:00', '3:30'],['3:30', '4:00'],['4:00', '4:30'],['4:30', '5:00']]
- time_array = [[8.5, 9.0], [9.0, 9.5], [9.5, 10.0], [10.0, 10.5], [10.5, 11.0], [11.0, 11.5], [11.5, 12.0], [13.0, 13.5], [13.5, 14.0], [14.0, 14.5], [14.5, 15.0], [15.0, 15.5], [15.5, 16.0], [16.0, 16.5], [16.5, 17.0]]
- # time_array = []
- # (8.5..17).step(0.5).each do |time|
- # time_array << time
- # end
- # time_slot = []
- # time_array.each_with_index do |x, i|
- # time_slot << [x, time_array[i+1]]
- # end
- time_used_array_to_num = []
- time_used_array.each do |time|
- temp_array1 = time[0].split(":")
- num1 = temp_array1[0].to_i
- num1 += 12 if num1 < 8
- if temp_array1[1] == "30"
- num1 += 0.5
- end
- temp_array2 = time[1].split(":")
- num2 = temp_array2[0].to_i
- num2 += 12 if num2 < 8
- if temp_array2[1] == "30"
- num2 += 0.5
- end
- time_used_array_to_num << [num1, num2]
- end
- expand_time_used_array = []
- time_used_array_to_num.each do |time|
- if time[1] - time[0] == 0.5
- expand_time_used_array << time
- else
- until time[0] == time[1] do
- expand_time_used_array << [time[0], time[0]+0.5]
- time[0] += 0.5
- end
- end
- end
- x = expand_time_used_array.uniq
- available_time = []
- time_array.each do |time|
- unless x.include?(time)
- available_time << time
- end
- end
- p available_time
- availe_time_to_s = []
- available_time.each do |time|
- if time[0] % 1 == 0
- time1 = time[0].to_i.to_s + ":00"
- else
- time1 = time[0].to_i.to_s + ":30"
- end
- if time[1] % 1 == 0
- time2 = time[1].to_i.to_s + ":00"
- else
- time2 = time[1].to_i.to_s + ":30"
- end
- availe_time_to_s << [time1, time2]
- end
- availe_time_to_s
- end
- team_availability([['9:00', '9:30'], ['9:00', '11:30'], ['10:00', '11:00'], ['2:30', '3:00'], ['2:30', '3:30']])
Add Comment
Please, Sign In to add comment