Index: app/controllers/application.rb =================================================================== --- app/controllers/application.rb (revision 1709) +++ app/controllers/application.rb (working copy) @@ -18,7 +18,9 @@ require 'uri' class ApplicationController < ActionController::Base - before_filter :user_setup, :check_if_login_required, :set_localization + before_filter :user_setup, :check_if_login_required, :set_localization, + :set_time_zone + filter_parameter_logging :password include Redmine::MenuManager::MenuController @@ -28,6 +30,10 @@ require_dependency "repository/#{scm.underscore}" end + def set_time_zone + Time.zone = User.current.time_zone if User.current + end + def current_role @current_role ||= User.current.role_for_project(@project) end Index: app/helpers/application_helper.rb =================================================================== --- app/helpers/application_helper.rb (revision 1709) +++ app/helpers/application_helper.rb (working copy) @@ -88,11 +88,10 @@ def format_time(time, include_date = true) return nil unless time time = time.to_time if time.is_a?(String) - zone = User.current.time_zone - local = zone ? time.in_time_zone(zone) : (time.utc? ? time.utc_to_local : time) @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format) @time_format ||= (Setting.time_format.blank? ? l(:general_fmt_time) : Setting.time_format) - include_date ? local.strftime("#{@date_format} #{@time_format}") : local.strftime(@time_format) + format = include_date ? "#{@date_format} #{@time_format}" : @time_format + time.strftime(format) end # Truncates and returns the string as a single line Index: config/environment.rb =================================================================== --- config/environment.rb (revision 1709) +++ config/environment.rb (working copy) @@ -43,8 +43,9 @@ # config.active_record.observers = :cacher, :garbage_collector config.active_record.observers = :message_observer - # Make Active Record use UTC-base instead of local time - # config.active_record.default_timezone = :utc + #turn on Rails' support of time zones. Place your server's timezone here, + # use rake time:zones:local to list seem-to-be suitable timezones. + config.time_zone = 'Moscow' # Use Active Record's schema dumper instead of SQL when creating the test database # (enables use of different database adapters for development and test environments) Index: lib/tasks/convert_database_times_to_utc.rake =================================================================== --- lib/tasks/convert_database_times_to_utc.rake (revision 0) +++ lib/tasks/convert_database_times_to_utc.rake (revision 0) @@ -0,0 +1,25 @@ +# Be sure to correct LOCAL_UTC_OFFSET and back up database prior to running. +namespace :redmine do + desc 'Migrates existing time values in database to UTC.' + task :convert_database_times_to_utc => :environment do + LOCAL_UTC_OFFSET = 1.hours #Time offset of server that Redmine was running on. 1.hours is for e.g. BST. + [Issue, Journal, Version, Message, Attachment, Project, Changeset, News, + TimeEntry, WikiPage, WikiContent, WikiContent::Version].each do |klass| + puts "\n\nUpdating #{klass} timestamps to UTC" + time_columns = klass.columns.select do |c| + [:datetime, :timestamp].include?(c.type) + end + klass.all.each do |obj| + modified = false + time_columns.each do |c| + obj.send("#{c.name}=", obj.send("#{c.name}") - LOCAL_UTC_OFFSET) + modified = true + end + if modified + raise "error saving #{obj}" if !obj.save_with_validation(false) + print '.' + end + end + end + end +end