Skip to content

Instantly share code, notes, and snippets.

@roramirez
Created June 10, 2019 17:18
Show Gist options
  • Save roramirez/50c4d0c301efcf321d6ce06c09b5dcf9 to your computer and use it in GitHub Desktop.
Save roramirez/50c4d0c301efcf321d6ce06c09b5dcf9 to your computer and use it in GitHub Desktop.
def in_range_time_from_db(from, to, value=Time.now)
# The `time` types are storage in the database in format HH:MM:SS.
# `ActiveRecord` returns into theTime type '2000-01-01 HH:MM:SS'
# This function return these times [`from`, `to`] to present date
# and checks if the `value` is in this range period
from = from.to_time.strftime("%T")
to = to.to_time.strftime("%T")
from = Time.parse(from)
to = Time.parse(to)
(from..to).include?(value)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment