diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-05-07 10:42:22 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-05-07 10:42:22 +0000 |
commit | ed50d42210eaf7ca216e9cd3a043b36aa68eb51d (patch) | |
tree | fbc801683ee622f43e790ec6cf2785fd8f94a43c /app/models | |
parent | 40c9c3e922e15ab7d88b5d06c60e51ed1ba40a7f (diff) | |
download | redmine-ed50d42210eaf7ca216e9cd3a043b36aa68eb51d.tar.gz redmine-ed50d42210eaf7ca216e9cd3a043b36aa68eb51d.zip |
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
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/issue.rb | 4 | ||||
-rw-r--r-- | app/models/mail_handler.rb | 2 | ||||
-rw-r--r-- | app/models/project.rb | 2 | ||||
-rw-r--r-- | app/models/query.rb | 14 | ||||
-rw-r--r-- | app/models/user.rb | 1 | ||||
-rw-r--r-- | app/models/version.rb | 6 |
6 files changed, 15 insertions, 14 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb index 7d7db13e1..0ee8ff3d3 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -807,14 +807,14 @@ class Issue < ActiveRecord::Base # Returns true if the issue is overdue def overdue? - due_date.present? && (due_date < Date.today) && !closed? + due_date.present? && (due_date < User.current.today) && !closed? end # Is the amount of work done less than it should for the due date def behind_schedule? return false if start_date.nil? || due_date.nil? done_date = start_date + ((due_date - start_date + 1) * done_ratio / 100).floor - return done_date <= Date.today + return done_date <= User.current.today end # Does this issue have children? diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index d5332e2e6..40bd02a07 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -206,7 +206,7 @@ class MailHandler < ActionMailer::Base issue.subject = '(no subject)' end issue.description = cleaned_up_text_body - issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date? + issue.start_date ||= User.current.today if Setting.default_issue_start_date_to_creation_date? issue.is_private = (handler_options[:issue][:is_private] == '1') # add To and Cc as watchers before saving so the watchers can reply to Redmine diff --git a/app/models/project.rb b/app/models/project.rb index 2e3a106f7..dee2e6dfd 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -594,7 +594,7 @@ class Project < ActiveRecord::Base end def overdue? - active? && !due_date.nil? && (due_date < Date.today) + active? && !due_date.nil? && (due_date < User.current.today) end # Returns the percent completed for this project, based on the diff --git a/app/models/query.rb b/app/models/query.rb index 68beb3c97..02e3f6cab 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -874,32 +874,32 @@ class Query < ActiveRecord::Base when "w" # = this week first_day_of_week = l(:general_first_day_of_week).to_i - day_of_week = Date.today.cwday + day_of_week = User.current.today.cwday days_ago = (day_of_week >= first_day_of_week ? day_of_week - first_day_of_week : day_of_week + 7 - first_day_of_week) sql = relative_date_clause(db_table, db_field, - days_ago, - days_ago + 6, is_custom_filter) when "lw" # = last week first_day_of_week = l(:general_first_day_of_week).to_i - day_of_week = Date.today.cwday + day_of_week = User.current.today.cwday days_ago = (day_of_week >= first_day_of_week ? day_of_week - first_day_of_week : day_of_week + 7 - first_day_of_week) sql = relative_date_clause(db_table, db_field, - days_ago - 7, - days_ago - 1, is_custom_filter) when "l2w" # = last 2 weeks first_day_of_week = l(:general_first_day_of_week).to_i - day_of_week = Date.today.cwday + day_of_week = User.current.today.cwday days_ago = (day_of_week >= first_day_of_week ? day_of_week - first_day_of_week : day_of_week + 7 - first_day_of_week) sql = relative_date_clause(db_table, db_field, - days_ago - 14, - days_ago - 1, is_custom_filter) when "m" # = this month - date = Date.today + date = User.current.today sql = date_clause(db_table, db_field, date.beginning_of_month, date.end_of_month, is_custom_filter) when "lm" # = last month - date = Date.today.prev_month + date = User.current.today.prev_month sql = date_clause(db_table, db_field, date.beginning_of_month, date.end_of_month, is_custom_filter) when "y" # = this year - date = Date.today + date = User.current.today sql = date_clause(db_table, db_field, date.beginning_of_year, date.end_of_year, is_custom_filter) when "~" sql = sql_contains("#{db_table}.#{db_field}", value.first) @@ -999,7 +999,7 @@ class Query < ActiveRecord::Base # Returns a SQL clause for a date or datetime field using relative dates. def relative_date_clause(table, field, days_from, days_to, is_custom_filter) - date_clause(table, field, (days_from ? Date.today + days_from : nil), (days_to ? Date.today + days_to : nil), is_custom_filter) + date_clause(table, field, (days_from ? User.current.today + days_from : nil), (days_to ? User.current.today + days_to : nil), is_custom_filter) end # Returns a Date or Time from the given filter value diff --git a/app/models/user.rb b/app/models/user.rb index b999361f1..d97b38bc1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -512,6 +512,7 @@ class User < Principal if time_zone.nil? Date.today else + # TODO replace with time_zone.today Time.now.in_time_zone(time_zone).to_date end end diff --git a/app/models/version.rb b/app/models/version.rb index ad3d816fb..bc71b72e9 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -104,7 +104,7 @@ class Version < ActiveRecord::Base # Returns true if the version is completed: closed or due date reached and no open issues def completed? - closed? || (effective_date && (effective_date < Date.today) && (open_issues_count == 0)) + closed? || (effective_date && (effective_date < User.current.today) && (open_issues_count == 0)) end def behind_schedule? @@ -112,7 +112,7 @@ class Version < ActiveRecord::Base return false elsif due_date && start_date done_date = start_date + ((due_date - start_date+1)* completed_percent/100).floor - return done_date <= Date.today + return done_date <= User.current.today else false # No issues so it's not late end @@ -141,7 +141,7 @@ class Version < ActiveRecord::Base # Returns true if the version is overdue: due date reached and some open issues def overdue? - effective_date && (effective_date < Date.today) && (open_issues_count > 0) + effective_date && (effective_date < User.current.today) && (open_issues_count > 0) end # Returns assigned issues count |