Defect #30288 » fix-30288-v1.patch
| app/models/user.rb | ||
|---|---|---|
| 542 | 542 | |
| 543 | 543 |
# Returns the day of +time+ according to user's time zone |
| 544 | 544 |
def time_to_date(time) |
| 545 |
if time_zone.nil? |
|
| 546 |
time.to_date |
|
| 545 |
self.convert_time_to_user_timezone(time).to_date |
|
| 546 |
end |
|
| 547 | ||
| 548 |
def convert_time_to_user_timezone(time) |
|
| 549 |
if self.time_zone |
|
| 550 |
time.in_time_zone(self.time_zone) |
|
| 547 | 551 |
else |
| 548 |
time.in_time_zone(time_zone).to_date
|
|
| 552 |
time.utc? ? time.localtime : time
|
|
| 549 | 553 |
end |
| 550 | 554 |
end |
| 551 | 555 | |
| lib/redmine/i18n.rb | ||
|---|---|---|
| 77 | 77 |
options = {}
|
| 78 | 78 |
options[:format] = (Setting.time_format.blank? ? :time : Setting.time_format) |
| 79 | 79 |
time = time.to_time if time.is_a?(String) |
| 80 |
zone = user.time_zone |
|
| 81 |
local = zone ? time.in_time_zone(zone) : (time.utc? ? time.localtime : time) |
|
| 80 |
local = user.convert_time_to_user_timezone(time) |
|
| 82 | 81 |
(include_date ? "#{format_date(local)} " : "") + ::I18n.l(local, options)
|
| 83 | 82 |
end |
| 84 | 83 | |
| test/functional/issues_controller_test.rb | ||
|---|---|---|
| 353 | 353 |
end |
| 354 | 354 |
end |
| 355 | 355 | |
| 356 |
def test_index_grouped_by_created_on |
|
| 356 |
def test_index_grouped_by_created_on_if_time_zone_is_utc
|
|
| 357 | 357 |
skip unless IssueQuery.new.groupable_columns.detect {|c| c.name == :created_on}
|
| 358 |
|
|
| 358 |
@request.session[:user_id] = 2 |
|
| 359 |
User.find(2).pref.update(time_zone: 'UTC') |
|
| 360 | ||
| 359 | 361 |
get :index, :params => {
|
| 360 | 362 |
:set_filter => 1, |
| 361 | 363 |
:group_by => 'created_on' |
| 362 | 364 |
} |
| 363 | 365 |
assert_response :success |
| 364 |
|
|
| 366 | ||
| 365 | 367 |
assert_select 'tr.group span.name', :text => '07/19/2006' do |
| 366 | 368 |
assert_select '+ span.count', :text => '2' |
| 367 | 369 |
end |
| 368 | 370 |
end |
| 369 |
|
|
| 371 | ||
| 372 |
def test_index_grouped_by_created_on_if_time_zone_is_nil |
|
| 373 |
skip unless IssueQuery.new.groupable_columns.detect {|c| c.name == :created_on}
|
|
| 374 |
current_user = User.find(2) |
|
| 375 |
@request.session[:user_id] = current_user.id |
|
| 376 |
current_user.pref.update(time_zone: nil) |
|
| 377 | ||
| 378 |
get :index, :params => {
|
|
| 379 |
:set_filter => 1, |
|
| 380 |
:group_by => 'created_on' |
|
| 381 |
} |
|
| 382 |
assert_response :success |
|
| 383 | ||
| 384 |
# group_name depends on localtime |
|
| 385 |
group_name = format_date(Issue.second.created_on.localtime) |
|
| 386 |
assert_select 'tr.group span.name', :text => group_name do |
|
| 387 |
assert_select '+ span.count', :text => '2' |
|
| 388 |
end |
|
| 389 |
end |
|
| 390 | ||
| 370 | 391 |
def test_index_grouped_by_created_on_as_pdf |
| 371 | 392 |
skip unless IssueQuery.new.groupable_columns.detect {|c| c.name == :created_on}
|
| 372 | 393 |
|
| test/unit/user_test.rb | ||
|---|---|---|
| 584 | 584 |
assert_equal '2012-05-15', User.find(1).time_to_date(time).to_s |
| 585 | 585 | |
| 586 | 586 |
preference.update_attribute :time_zone, '' |
| 587 |
assert_equal '2012-05-15', User.find(1).time_to_date(time).to_s |
|
| 587 |
assert_equal time.localtime.to_date.to_s, User.find(1).time_to_date(time).to_s |
|
| 588 |
end |
|
| 589 | ||
| 590 |
def test_convert_time_to_user_timezone_should_return_the_time_according_to_user_time_zone |
|
| 591 |
preference = User.find(1).pref |
|
| 592 |
time = Time.gm(2012, 05, 15, 23, 30).utc # 2012-05-15 23:30 UTC |
|
| 593 |
time_not_utc = Time.new(2012, 05, 15, 23, 30) |
|
| 594 | ||
| 595 |
preference.update_attribute :time_zone, 'Baku' # UTC+5 |
|
| 596 |
assert_equal '2012-05-16 04:30:00 +0500', User.find(1).convert_time_to_user_timezone(time).to_s |
|
| 597 | ||
| 598 |
preference.update_attribute :time_zone, 'La Paz' # UTC-4 |
|
| 599 |
assert_equal '2012-05-15 19:30:00 -0400', User.find(1).convert_time_to_user_timezone(time).to_s |
|
| 600 | ||
| 601 |
preference.update_attribute :time_zone, '' |
|
| 602 |
assert_equal time.localtime.to_s, User.find(1).convert_time_to_user_timezone(time).to_s |
|
| 603 |
assert_equal time_not_utc, User.find(1).convert_time_to_user_timezone(time_not_utc) |
|
| 588 | 604 |
end |
| 589 | 605 | |
| 590 | 606 |
def test_fields_for_order_statement_should_return_fields_according_user_format_setting |
- « Previous
- 1
- 2
- Next »