From 129e93dd12841e5fba21aacf9c0ab899adb3a2ad Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 14 Jun 2017 01:15:26 +0200 Subject: [PATCH] Use Time.current converted to Date by the database DirectMessage today scope Why: * Database stores created_at as timestamp with the timezone, so when comparing DATE(created_at) to something we have to convert it to DATE as well with the postresql native function, but using Time.current instead of Date.current to take into account the user timezone --- app/models/direct_message.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/direct_message.rb b/app/models/direct_message.rb index b36cca705..ae14e652d 100644 --- a/app/models/direct_message.rb +++ b/app/models/direct_message.rb @@ -8,7 +8,7 @@ class DirectMessage < ActiveRecord::Base validates :receiver, presence: true validate :max_per_day - scope :today, lambda { where('DATE(created_at) = ?', Date.current) } + scope :today, lambda { where('DATE(created_at) = DATE(?)', Time.current) } def max_per_day return if errors.any?