Fixed time zone issues introduced by r9719 (#10996).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9726 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
84084b0168
commit
189be55235
|
@ -43,7 +43,7 @@ class ActivitiesController < ApplicationController
|
|||
if events.empty? || stale?(:etag => [@activity.scope, @date_to, @date_from, @with_subprojects, @author, events.first, User.current, current_language])
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
@events_by_day = events.group_by(&:event_date)
|
||||
@events_by_day = events.group_by {|event| User.current.time_to_date(event.event_datetime)}
|
||||
render :layout => false if request.xhr?
|
||||
}
|
||||
format.atom {
|
||||
|
|
|
@ -178,7 +178,7 @@ module ApplicationHelper
|
|||
end
|
||||
|
||||
def format_activity_day(date)
|
||||
date == Date.today ? l(:label_today).titleize : format_date(date)
|
||||
date == User.current.today ? l(:label_today).titleize : format_date(date)
|
||||
end
|
||||
|
||||
def format_activity_description(text)
|
||||
|
@ -352,7 +352,7 @@ module ApplicationHelper
|
|||
def time_tag(time)
|
||||
text = distance_of_time_in_words(Time.now, time)
|
||||
if @project
|
||||
link_to(text, {:controller => 'activities', :action => 'index', :id => @project, :from => time.to_date}, :title => format_time(time))
|
||||
link_to(text, {:controller => 'activities', :action => 'index', :id => @project, :from => User.current.time_to_date(time)}, :title => format_time(time))
|
||||
else
|
||||
content_tag('acronym', text, :title => format_time(time))
|
||||
end
|
||||
|
|
|
@ -848,12 +848,18 @@ class Query < ActiveRecord::Base
|
|||
s = []
|
||||
if from
|
||||
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)])
|
||||
from_yesterday_time = Time.local(from_yesterday.year, from_yesterday.month, from_yesterday.day)
|
||||
if self.class.default_timezone == :utc
|
||||
from_yesterday_time = from_yesterday_time.utc
|
||||
end
|
||||
s << ("#{table}.#{field} > '%s'" % [connection.quoted_date(from_yesterday_time.end_of_day)])
|
||||
end
|
||||
if to
|
||||
to_utc = Time.gm(to.year, to.month, to.day)
|
||||
s << ("#{table}.#{field} <= '%s'" % [connection.quoted_date(to_utc.end_of_day)])
|
||||
to_time = Time.local(to.year, to.month, to.day)
|
||||
if self.class.default_timezone == :utc
|
||||
to_time = to_time.utc
|
||||
end
|
||||
s << ("#{table}.#{field} <= '%s'" % [connection.quoted_date(to_time.end_of_day)])
|
||||
end
|
||||
s.join(' AND ')
|
||||
end
|
||||
|
|
|
@ -370,6 +370,15 @@ class User < Principal
|
|||
end
|
||||
end
|
||||
|
||||
# Returns the day of +time+ according to user's time zone
|
||||
def time_to_date(time)
|
||||
if time_zone.nil?
|
||||
time.to_date
|
||||
else
|
||||
time.in_time_zone(time_zone).to_date
|
||||
end
|
||||
end
|
||||
|
||||
def logged?
|
||||
true
|
||||
end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
---
|
||||
issues_001:
|
||||
created_on: <%= 3.days.ago.to_date.to_s(:db) %>
|
||||
created_on: <%= 3.days.ago.to_s(:db) %>
|
||||
project_id: 1
|
||||
updated_on: <%= 1.day.ago.to_date.to_s(:db) %>
|
||||
updated_on: <%= 1.day.ago.to_s(:db) %>
|
||||
priority_id: 4
|
||||
subject: Can't print recipes
|
||||
id: 1
|
||||
|
@ -60,9 +60,9 @@ issues_003:
|
|||
lft: 1
|
||||
rgt: 2
|
||||
issues_004:
|
||||
created_on: <%= 5.days.ago.to_date.to_s(:db) %>
|
||||
created_on: <%= 5.days.ago.to_s(:db) %>
|
||||
project_id: 2
|
||||
updated_on: <%= 2.days.ago.to_date.to_s(:db) %>
|
||||
updated_on: <%= 2.days.ago.to_s(:db) %>
|
||||
priority_id: 4
|
||||
subject: Issue on project 2
|
||||
id: 4
|
||||
|
@ -77,9 +77,9 @@ issues_004:
|
|||
lft: 1
|
||||
rgt: 2
|
||||
issues_005:
|
||||
created_on: <%= 5.days.ago.to_date.to_s(:db) %>
|
||||
created_on: <%= 5.days.ago.to_s(:db) %>
|
||||
project_id: 3
|
||||
updated_on: <%= 2.days.ago.to_date.to_s(:db) %>
|
||||
updated_on: <%= 2.days.ago.to_s(:db) %>
|
||||
priority_id: 4
|
||||
subject: Subproject issue
|
||||
id: 5
|
||||
|
@ -94,9 +94,9 @@ issues_005:
|
|||
lft: 1
|
||||
rgt: 2
|
||||
issues_006:
|
||||
created_on: <%= 1.minute.ago.to_date.to_s(:db) %>
|
||||
created_on: <%= 1.minute.ago.to_s(:db) %>
|
||||
project_id: 5
|
||||
updated_on: <%= 1.minute.ago.to_date.to_s(:db) %>
|
||||
updated_on: <%= 1.minute.ago.to_s(:db) %>
|
||||
priority_id: 4
|
||||
subject: Issue of a private subproject
|
||||
id: 6
|
||||
|
@ -113,9 +113,9 @@ issues_006:
|
|||
lft: 1
|
||||
rgt: 2
|
||||
issues_007:
|
||||
created_on: <%= 10.days.ago.to_date.to_s(:db) %>
|
||||
created_on: <%= 10.days.ago.to_s(:db) %>
|
||||
project_id: 1
|
||||
updated_on: <%= 10.days.ago.to_date.to_s(:db) %>
|
||||
updated_on: <%= 10.days.ago.to_s(:db) %>
|
||||
priority_id: 5
|
||||
subject: Issue due today
|
||||
id: 7
|
||||
|
@ -133,9 +133,9 @@ issues_007:
|
|||
lft: 1
|
||||
rgt: 2
|
||||
issues_008:
|
||||
created_on: <%= 10.days.ago.to_date.to_s(:db) %>
|
||||
created_on: <%= 10.days.ago.to_s(:db) %>
|
||||
project_id: 1
|
||||
updated_on: <%= 10.days.ago.to_date.to_s(:db) %>
|
||||
updated_on: <%= 10.days.ago.to_s(:db) %>
|
||||
priority_id: 5
|
||||
subject: Closed issue
|
||||
id: 8
|
||||
|
@ -153,9 +153,9 @@ issues_008:
|
|||
lft: 1
|
||||
rgt: 2
|
||||
issues_009:
|
||||
created_on: <%= 1.minute.ago.to_date.to_s(:db) %>
|
||||
created_on: <%= 1.minute.ago.to_s(:db) %>
|
||||
project_id: 5
|
||||
updated_on: <%= 1.minute.ago.to_date.to_s(:db) %>
|
||||
updated_on: <%= 1.minute.ago.to_s(:db) %>
|
||||
priority_id: 5
|
||||
subject: Blocked Issue
|
||||
id: 9
|
||||
|
@ -172,9 +172,9 @@ issues_009:
|
|||
lft: 1
|
||||
rgt: 2
|
||||
issues_010:
|
||||
created_on: <%= 1.minute.ago.to_date.to_s(:db) %>
|
||||
created_on: <%= 1.minute.ago.to_s(:db) %>
|
||||
project_id: 5
|
||||
updated_on: <%= 1.minute.ago.to_date.to_s(:db) %>
|
||||
updated_on: <%= 1.minute.ago.to_s(:db) %>
|
||||
priority_id: 5
|
||||
subject: Issue Doing the Blocking
|
||||
id: 10
|
||||
|
@ -191,9 +191,9 @@ issues_010:
|
|||
lft: 1
|
||||
rgt: 2
|
||||
issues_011:
|
||||
created_on: <%= 3.days.ago.to_date.to_s(:db) %>
|
||||
created_on: <%= 3.days.ago.to_s(:db) %>
|
||||
project_id: 1
|
||||
updated_on: <%= 1.day.ago.to_date.to_s(:db) %>
|
||||
updated_on: <%= 1.day.ago.to_s(:db) %>
|
||||
priority_id: 5
|
||||
subject: Closed issue on a closed version
|
||||
id: 11
|
||||
|
@ -210,9 +210,9 @@ issues_011:
|
|||
lft: 1
|
||||
rgt: 2
|
||||
issues_012:
|
||||
created_on: <%= 3.days.ago.to_date.to_s(:db) %>
|
||||
created_on: <%= 3.days.ago.to_s(:db) %>
|
||||
project_id: 1
|
||||
updated_on: <%= 1.day.ago.to_date.to_s(:db) %>
|
||||
updated_on: <%= 1.day.ago.to_s(:db) %>
|
||||
priority_id: 5
|
||||
subject: Closed issue on a locked version
|
||||
id: 12
|
||||
|
@ -229,9 +229,9 @@ issues_012:
|
|||
lft: 1
|
||||
rgt: 2
|
||||
issues_013:
|
||||
created_on: <%= 5.days.ago.to_date.to_s(:db) %>
|
||||
created_on: <%= 5.days.ago.to_s(:db) %>
|
||||
project_id: 3
|
||||
updated_on: <%= 2.days.ago.to_date.to_s(:db) %>
|
||||
updated_on: <%= 2.days.ago.to_s(:db) %>
|
||||
priority_id: 4
|
||||
subject: Subproject issue two
|
||||
id: 13
|
||||
|
@ -247,9 +247,9 @@ issues_013:
|
|||
rgt: 2
|
||||
issues_014:
|
||||
id: 14
|
||||
created_on: <%= 15.days.ago.to_date.to_s(:db) %>
|
||||
created_on: <%= 15.days.ago.to_s(:db) %>
|
||||
project_id: 3
|
||||
updated_on: <%= 15.days.ago.to_date.to_s(:db) %>
|
||||
updated_on: <%= 15.days.ago.to_s(:db) %>
|
||||
priority_id: 5
|
||||
subject: Private issue on public project
|
||||
fixed_version_id:
|
||||
|
|
|
@ -425,6 +425,37 @@ class UserTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_today_should_return_the_day_according_to_user_time_zone
|
||||
preference = User.find(1).pref
|
||||
date = Date.new(2012, 05, 15)
|
||||
time = Time.gm(2012, 05, 15, 23, 30).utc # 2012-05-15 23:30 UTC
|
||||
Date.stubs(:today).returns(date)
|
||||
Time.stubs(:now).returns(time)
|
||||
|
||||
preference.update_attribute :time_zone, 'Baku' # UTC+4
|
||||
assert_equal '2012-05-16', User.find(1).today.to_s
|
||||
|
||||
preference.update_attribute :time_zone, 'La Paz' # UTC-4
|
||||
assert_equal '2012-05-15', User.find(1).today.to_s
|
||||
|
||||
preference.update_attribute :time_zone, ''
|
||||
assert_equal '2012-05-15', User.find(1).today.to_s
|
||||
end
|
||||
|
||||
def test_time_to_date_should_return_the_date_according_to_user_time_zone
|
||||
preference = User.find(1).pref
|
||||
time = Time.gm(2012, 05, 15, 23, 30).utc # 2012-05-15 23:30 UTC
|
||||
|
||||
preference.update_attribute :time_zone, 'Baku' # UTC+4
|
||||
assert_equal '2012-05-16', User.find(1).time_to_date(time).to_s
|
||||
|
||||
preference.update_attribute :time_zone, 'La Paz' # UTC-4
|
||||
assert_equal '2012-05-15', User.find(1).time_to_date(time).to_s
|
||||
|
||||
preference.update_attribute :time_zone, ''
|
||||
assert_equal '2012-05-15', User.find(1).time_to_date(time).to_s
|
||||
end
|
||||
|
||||
def test_fields_for_order_statement_should_return_fields_according_user_format_setting
|
||||
with_settings :user_format => 'lastname_coma_firstname' do
|
||||
assert_equal ['users.lastname', 'users.firstname', 'users.id'], User.fields_for_order_statement
|
||||
|
|
Loading…
Reference in New Issue