diff --git a/lib/redmine/database.rb b/lib/redmine/database.rb index 0f0876157..bbc90c810 100644 --- a/lib/redmine/database.rb +++ b/lib/redmine/database.rb @@ -69,21 +69,16 @@ module Redmine # Returns a SQL statement to cast a timestamp column to a date given a time zone # Returns nil if not implemented for the current database def timestamp_to_date(column, time_zone) + return nil unless postgresql? || mysql? + # param:time_zone or config.time_zone + identifier = ActiveSupport::TimeZone.find_tzinfo((time_zone || Time.zone).name).identifier + if postgresql? - if time_zone - identifier = ActiveSupport::TimeZone.find_tzinfo(time_zone.name).identifier - "(#{column}::timestamptz AT TIME ZONE '#{identifier}')::date" - else - "#{column}::date" - end - elsif mysql? - if time_zone - user_identifier = ActiveSupport::TimeZone.find_tzinfo(time_zone.name).identifier - local_identifier = ActiveSupport::TimeZone.find_tzinfo(Time.zone.name).identifier - "DATE(CONVERT_TZ(#{column},'#{local_identifier}', '#{user_identifier}'))" - else - "DATE(#{column})" - end + "(#{column}::timestamptz AT TIME ZONE '#{identifier}')::date" + else + # MySQL: + # convert from local time zone to tz + "DATE(CONVERT_TZ(#{column}, @@session.time_zone, '#{identifier}'))" end end diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 50ba64a88..87d53ee8b 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -443,9 +443,8 @@ class IssuesControllerTest < Redmine::ControllerTest } ) assert_response :success - # group_name depends on localtime - group_name = format_date(Issue.second.created_on.localtime) + group_name = format_date(User.current.time_to_date(Issue.second.created_on)) assert_select 'tr.group span.name', :text => group_name do assert_select '+ span.count', :text => '2' end