diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-05-07 10:58:49 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-05-07 10:58:49 +0000 |
commit | eafd585dbe958443cb9d06d217b708cd9f48ea37 (patch) | |
tree | b48d5bacf409555fc58d81e13062606fb6f9cdc8 /app/models/query.rb | |
parent | ed50d42210eaf7ca216e9cd3a043b36aa68eb51d (diff) | |
download | redmine-eafd585dbe958443cb9d06d217b708cd9f48ea37.tar.gz redmine-eafd585dbe958443cb9d06d217b708cd9f48ea37.zip |
Fixes Query#date_clause timezone handling (#22320).
When querying time fields based on date values these should be interpreted
in the user's time zone, since that's what a user usually expects.
Patch by Jens Kraemer.
git-svn-id: http://svn.redmine.org/redmine/trunk@15381 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/query.rb')
-rw-r--r-- | app/models/query.rb | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/app/models/query.rb b/app/models/query.rb index 02e3f6cab..d1315d5de 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -971,12 +971,20 @@ class Query < ActiveRecord::Base end end + def date_for_user_time_zone(y, m, d) + if tz = User.current.time_zone + tz.local y, m, d + else + Time.local y, m, d + end + end + # Returns a SQL clause for a date or datetime field. def date_clause(table, field, from, to, is_custom_filter) s = [] if from if from.is_a?(Date) - from = Time.local(from.year, from.month, from.day).yesterday.end_of_day + from = date_for_user_time_zone(from.year, from.month, from.day).yesterday.end_of_day else from = from - 1 # second end @@ -987,7 +995,7 @@ class Query < ActiveRecord::Base end if to if to.is_a?(Date) - to = Time.local(to.year, to.month, to.day).end_of_day + to = date_for_user_time_zone(to.year, to.month, to.day).end_of_day end if self.class.default_timezone == :utc to = to.utc |