module Today::ActiveRecord
Public Instance Methods
today(*argv)
click to toggle source
usage today today(:updated_at) today(:created_at, Time.now) today(at: Time.now) today(key: updated_at, at: Time.now)
# File lib/today/active_record.rb, line 12 def today *argv if argv.first.is_a? Hash key = argv[0][:key] || :created_at at = argv[0][:at] || Date.today else key = argv[0] || :created_at at = argv[1] || Date.today end where("#{key.to_s} >= ?", at.at_beginning_of_day) .where("#{key.to_s} <= ?", at.at_end_of_day) end
tomorrow(key=:created_at)
click to toggle source
# File lib/today/active_record.rb, line 30 def tomorrow key=:created_at at = Date.today + 1 today(key, at) end
yesterday(key=:created_at)
click to toggle source
# File lib/today/active_record.rb, line 25 def yesterday key=:created_at at = Date.today - 1 today(key, at) end