From ed50d42210eaf7ca216e9cd3a043b36aa68eb51d Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 7 May 2016 10:42:22 +0000 Subject: Replace Date.today with User.current.today (#22320). Depending on the offset between a user's configured timezone and the server timezone, Date.today may be more or less often wrong from the user's perspective, leading to things like issues marked as overdue too early or too late, or yesterday / tomorrow being displayed / selected where 'today' is intended. A test case illustrating the problem with Issue#overdue? is included Patch by Jens Kraemer. git-svn-id: http://svn.redmine.org/redmine/trunk@15379 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- test/unit/issue_test.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test/unit') diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index 03dd57229..d7c7d231b 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -2756,4 +2756,30 @@ class IssueTest < ActiveSupport::TestCase issue.reload.assigned_to = nil assert_equal group, issue.assigned_to_was end + + def test_issue_overdue_should_respect_user_timezone + user_in_europe = users(:users_001) + user_in_europe.pref.update_attribute :time_zone, 'UTC' + + user_in_asia = users(:users_002) + user_in_asia.pref.update_attribute :time_zone, 'Hongkong' + + issue = Issue.generate! :due_date => Date.parse('2016-03-20') + + # server time is UTC + time = Time.parse '2016-03-20 20:00 UTC' + Time.stubs(:now).returns(time) + Date.stubs(:today).returns(time.to_date) + + # for a user in the same time zone as the server the issue is not overdue + # yet + User.current = user_in_europe + assert !issue.overdue? + + # at the same time, a user in East Asia looks at the issue - it's already + # March 21st and the issue should be marked overdue + User.current = user_in_asia + assert issue.overdue? + + end end -- cgit v1.2.3