Guest User

Untitled

a guest
Mar 29th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.06 KB | None | 0 0
  1.   def open?(current_time: Time.now.change(sec: 0))
  2.     current_business_hour = business_hours.where('week_day = ? AND open_at <= ? AND close_at >= ?', current_time.wday, current_time, current_time).first
  3.     if current_business_hour
  4.       safe_closing_hour = current_business_hour.close_at - 30.minutes
  5.       if current_time.strftime('%H:%M') >= '23:29'
  6.         next_opening_hour = business_hours.where(week_day: DateTime.now.tomorrow.wday).order(:open_at).first
  7.         if next_opening_hour
  8.         if next_opening_hour.open_at.strftime('%H:%M') == '00:00'
  9.           if next_opening_hour.close_at.strftime('%H:%M') >= '00:29'
  10.             true
  11.           elsif (next_opening_hour.close_at - 30.minutes).strftime('%H:%M') < current_time.strftime('%H:%M')
  12.             false
  13.           else
  14.             true
  15.           end
  16.         else
  17.           false
  18.         end
  19.       else
  20.         false
  21.       end
  22.       elsif safe_closing_hour.strftime('%H:%M') < current_time.strftime('%H:%M')
  23.         false
  24.       else
  25.         true
  26.       end
  27.     else
  28.       false
  29.     end
  30.   end
Add Comment
Please, Sign In to add comment