From a17fcac8226473feb0f248c54ba2a829dd5bcd54 Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Fri, 7 Oct 2011 00:23:05 +0000 Subject: [PATCH] Rails3: model: query: parse dates using UTC (ruby 1.9 inside) (#4796) On Rails 3.0 and Ruby 1.8.7 in Japan (UTC+9), tests fails with following messages. test_operator_date_equals(QueryTest) [test/unit/query_test.rb:206]: <"(issues.due_date > '2011-07-09 14:59:59.999999' AND issues.due_date <= '2011-07-10 14:59:59.999999') AND (issue_statuses.is_closed='f')"> expected to be =~ '2011-07-09 23:59:59(\.9+)?' AND issues\.due_date <= '2011-07-10 23:59:59(\.9+)?/>. Contributed by Sylvain Utard. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7591 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/query.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/query.rb b/app/models/query.rb index b717ecbc2..c79677e2b 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -769,10 +769,13 @@ class Query < ActiveRecord::Base def date_clause(table, field, from, to) s = [] if from - s << ("#{table}.#{field} > '%s'" % [connection.quoted_date((from - 1).to_time.end_of_day)]) + from_yesterday = from - 1 + from_yesterday_utc = Time.gm(from_yesterday.year, from_yesterday.month, from_yesterday.day) + s << ("#{table}.#{field} > '%s'" % [connection.quoted_date(from_yesterday_utc.end_of_day)]) end if to - s << ("#{table}.#{field} <= '%s'" % [connection.quoted_date(to.to_time.end_of_day)]) + to_utc = Time.gm(to.year, to.month, to.day) + s << ("#{table}.#{field} <= '%s'" % [connection.quoted_date(to_utc.end_of_day)]) end s.join(' AND ') end