Patch #1705 » rails_timezones.patch
| app/controllers/application.rb (working copy) | ||
|---|---|---|
|
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
|
||
| ... | ... | |
|
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
|
||
| app/helpers/application_helper.rb (working copy) | ||
|---|---|---|
|
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
|
||
| config/environment.rb (working copy) | ||
|---|---|---|
|
# 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)
|
||
| lib/tasks/convert_database_times_to_utc.rake (revision 0) | ||
|---|---|---|
|
# 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
|
||