Skip to content

Instantly share code, notes, and snippets.

@k0nserv
Created May 13, 2014 20:37
Show Gist options
  • Save k0nserv/b6138b30d9a7d2b938f6 to your computer and use it in GitHub Desktop.
Save k0nserv/b6138b30d9a7d2b938f6 to your computer and use it in GitHub Desktop.
Opening hours
def hours(open, close)
(0..6).to_a.map do |x|
{
start: x * 24 + open,
end: x * 24 + close
}
end
end
# Could be binary search
def is_open?(hour, open_hours)
open_hours.each do |hours|
return true if hour >= hours[:start] and hour <= hours[:end]
end
return false
end
my_hours = hours 8, 18
is_open?(9, my_hours) # Open monday morning at 9?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment