Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def open?(current_time: Time.now.change(sec: 0))
- current_business_hour = business_hours.where('week_day = ? AND open_at <= ? AND close_at >= ?', current_time.wday, current_time, current_time).first
- if current_business_hour
- safe_closing_hour = current_business_hour.close_at - 30.minutes
- if current_time.strftime('%H:%M') >= '23:29'
- next_opening_hour = business_hours.where(week_day: DateTime.now.tomorrow.wday).order(:open_at).first
- if next_opening_hour
- if next_opening_hour.open_at.strftime('%H:%M') == '00:00'
- if next_opening_hour.close_at.strftime('%H:%M') >= '00:29'
- true
- elsif (next_opening_hour.close_at - 30.minutes).strftime('%H:%M') < current_time.strftime('%H:%M')
- false
- else
- true
- end
- else
- false
- end
- else
- false
- end
- elsif safe_closing_hour.strftime('%H:%M') < current_time.strftime('%H:%M')
- false
- else
- true
- end
- else
- false
- end
- end
Add Comment
Please, Sign In to add comment