addresses #927, make date searches time zone aware
This commit is contained in:
@@ -21,7 +21,11 @@ class PostQueryBuilder
|
||||
|
||||
case arr[0]
|
||||
when :eq
|
||||
relation.where(["#{field} = ?", arr[1]])
|
||||
if arr[1].is_a?(Time)
|
||||
relation.where("#{field} between ? and ?", arr[1].beginning_of_day, arr[1].end_of_day)
|
||||
else
|
||||
relation.where(["#{field} = ?", arr[1]])
|
||||
end
|
||||
|
||||
when :gt
|
||||
relation.where(["#{field} > ?", arr[1]])
|
||||
|
||||
@@ -3,12 +3,12 @@ module PostSets
|
||||
attr_reader :date, :scale
|
||||
|
||||
def initialize(date, scale)
|
||||
@date = date.blank? ? Date.today : date.to_date
|
||||
@date = date.blank? ? Time.zone.now : Time.zone.parse(date)
|
||||
@scale = scale
|
||||
end
|
||||
|
||||
def posts
|
||||
::Post.where("created_at between ? and ?", min_date, max_date + 1).order("score desc").limit(limit)
|
||||
::Post.where("created_at between ? and ?", min_date.beginning_of_day, max_date.end_of_day).order("score desc").limit(limit)
|
||||
end
|
||||
|
||||
def limit
|
||||
|
||||
@@ -174,7 +174,7 @@ class Tag < ActiveRecord::Base
|
||||
|
||||
when :date
|
||||
begin
|
||||
object.to_date
|
||||
Time.zone.parse(object)
|
||||
rescue Exception
|
||||
nil
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user