Guest User

Untitled

a guest
Jan 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. def team_availability(time_used_array)
  2. # 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']]
  3. 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]]
  4. # time_array = []
  5. # (8.5..17).step(0.5).each do |time|
  6. # time_array << time
  7. # end
  8. # time_slot = []
  9. # time_array.each_with_index do |x, i|
  10. # time_slot << [x, time_array[i+1]]
  11. # end
  12.  
  13. time_used_array_to_num = []
  14.  
  15. time_used_array.each do |time|
  16. temp_array1 = time[0].split(":")
  17. num1 = temp_array1[0].to_i
  18. num1 += 12 if num1 < 8
  19. if temp_array1[1] == "30"
  20. num1 += 0.5
  21. end
  22.  
  23. temp_array2 = time[1].split(":")
  24. num2 = temp_array2[0].to_i
  25. num2 += 12 if num2 < 8
  26. if temp_array2[1] == "30"
  27. num2 += 0.5
  28. end
  29. time_used_array_to_num << [num1, num2]
  30. end
  31.  
  32. expand_time_used_array = []
  33.  
  34. time_used_array_to_num.each do |time|
  35. if time[1] - time[0] == 0.5
  36. expand_time_used_array << time
  37. else
  38. until time[0] == time[1] do
  39. expand_time_used_array << [time[0], time[0]+0.5]
  40. time[0] += 0.5
  41. end
  42. end
  43. end
  44. x = expand_time_used_array.uniq
  45.  
  46. available_time = []
  47. time_array.each do |time|
  48. unless x.include?(time)
  49. available_time << time
  50. end
  51. end
  52. p available_time
  53. availe_time_to_s = []
  54. available_time.each do |time|
  55. if time[0] % 1 == 0
  56. time1 = time[0].to_i.to_s + ":00"
  57. else
  58. time1 = time[0].to_i.to_s + ":30"
  59. end
  60.  
  61. if time[1] % 1 == 0
  62. time2 = time[1].to_i.to_s + ":00"
  63. else
  64. time2 = time[1].to_i.to_s + ":30"
  65. end
  66. availe_time_to_s << [time1, time2]
  67. end
  68.  
  69. availe_time_to_s
  70. end
  71.  
  72.  
  73. 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