Project

General

Profile

Patch #22320 » 0001-Replace-Date.today-with-User.current.today.patch

Jens Krämer, 2016-03-26 09:14

View differences:

app/controllers/activities_controller.rb
27 27
      begin; @date_to = params[:from].to_date + 1; rescue; end
28 28
    end
29 29

  
30
    @date_to ||= Date.today + 1
30
    @date_to ||= User.current.today + 1
31 31
    @date_from = @date_to - @days
32 32
    @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
33 33
    if params[:user_id].present?
app/controllers/calendars_controller.rb
35 35
        @month = params[:month].to_i
36 36
      end
37 37
    end
38
    @year ||= Date.today.year
39
    @month ||= Date.today.month
38
    @year ||= User.current.today.year
39
    @month ||= User.current.today.month
40 40

  
41 41
    @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
42 42
    retrieve_query
app/controllers/issues_controller.rb
442 442
      @issue.project ||= @issue.allowed_target_projects.first
443 443
    end
444 444
    @issue.author ||= User.current
445
    @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
445
    @issue.start_date ||= User.current.today if Setting.default_issue_start_date_to_creation_date?
446 446

  
447 447
    attrs = (params[:issue] || {}).deep_dup
448 448
    if action_name == 'new' && params[:was_default_status] == attrs[:status_id]
app/controllers/repositories_controller.rb
350 350
  end
351 351

  
352 352
  def graph_commits_per_month(repository)
353
    @date_to = Date.today
353
    @date_to = User.current.today
354 354
    @date_from = @date_to << 11
355 355
    @date_from = Date.civil(@date_from.year, @date_from.month, 1)
356 356
    commits_by_day = Changeset.
......
369 369
    changes_by_day.each {|c| changes_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last }
370 370

  
371 371
    fields = []
372
    12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)}
372
    today = User.current.today
373
    12.times {|m| fields << month_name(((today.month - 1 - m) % 12) + 1)}
373 374

  
374 375
    graph = SVG::Graph::Bar.new(
375 376
      :height => 300,
app/helpers/application_helper.rb
252 252

  
253 253
  def due_date_distance_in_words(date)
254 254
    if date
255
      l((date < Date.today ? :label_roadmap_overdue : :label_roadmap_due_in), distance_of_date_in_words(Date.today, date))
255
      l((date < User.current.today ? :label_roadmap_overdue : :label_roadmap_due_in), distance_of_date_in_words(User.current.today, date))
256 256
    end
257 257
  end
258 258

  
app/helpers/my_helper.rb
65 65

  
66 66
  def timelog_items
67 67
    TimeEntry.
68
      where("#{TimeEntry.table_name}.user_id = ? AND #{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", User.current.id, Date.today - 6, Date.today).
68
      where("#{TimeEntry.table_name}.user_id = ? AND #{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", User.current.id, User.current.today - 6, User.current.today).
69 69
      joins(:activity, :project).
70 70
      references(:issue => [:tracker, :status]).
71 71
      includes(:issue => [:tracker, :status]).
app/helpers/settings_helper.rb
182 182
  # Returns the options for the date_format setting
183 183
  def date_format_setting_options(locale)
184 184
    Setting::DATE_FORMATS.map do |f|
185
      today = ::I18n.l(Date.today, :locale => locale, :format => f)
185
      today = ::I18n.l(User.current.today, :locale => locale, :format => f)
186 186
      format = f.gsub('%', '').gsub(/[dmY]/) do
187 187
        {'d' => 'dd', 'm' => 'mm', 'Y' => 'yyyy'}[$&]
188 188
      end
app/models/issue.rb
806 806

  
807 807
  # Returns true if the issue is overdue
808 808
  def overdue?
809
    due_date.present? && (due_date < Date.today) && !closed?
809
    due_date.present? && (due_date < User.current.today) && !closed?
810 810
  end
811 811

  
812 812
  # Is the amount of work done less than it should for the due date
813 813
  def behind_schedule?
814 814
    return false if start_date.nil? || due_date.nil?
815 815
    done_date = start_date + ((due_date - start_date + 1) * done_ratio / 100).floor
816
    return done_date <= Date.today
816
    return done_date <= User.current.today
817 817
  end
818 818

  
819 819
  # Does this issue have children?
app/models/mail_handler.rb
206 206
      issue.subject = '(no subject)'
207 207
    end
208 208
    issue.description = cleaned_up_text_body
209
    issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
209
    issue.start_date ||= User.current.today if Setting.default_issue_start_date_to_creation_date?
210 210
    issue.is_private = (handler_options[:issue][:is_private] == '1')
211 211

  
212 212
    # add To and Cc as watchers before saving so the watchers can reply to Redmine
app/models/project.rb
594 594
  end
595 595

  
596 596
  def overdue?
597
    active? && !due_date.nil? && (due_date < Date.today)
597
    active? && !due_date.nil? && (due_date < User.current.today)
598 598
  end
599 599

  
600 600
  # Returns the percent completed for this project, based on the
app/models/query.rb
869 869
    when "w"
870 870
      # = this week
871 871
      first_day_of_week = l(:general_first_day_of_week).to_i
872
      day_of_week = Date.today.cwday
872
      day_of_week = User.current.today.cwday
873 873
      days_ago = (day_of_week >= first_day_of_week ? day_of_week - first_day_of_week : day_of_week + 7 - first_day_of_week)
874 874
      sql = relative_date_clause(db_table, db_field, - days_ago, - days_ago + 6, is_custom_filter)
875 875
    when "lw"
876 876
      # = last week
877 877
      first_day_of_week = l(:general_first_day_of_week).to_i
878
      day_of_week = Date.today.cwday
878
      day_of_week = User.current.today.cwday
879 879
      days_ago = (day_of_week >= first_day_of_week ? day_of_week - first_day_of_week : day_of_week + 7 - first_day_of_week)
880 880
      sql = relative_date_clause(db_table, db_field, - days_ago - 7, - days_ago - 1, is_custom_filter)
881 881
    when "l2w"
882 882
      # = last 2 weeks
883 883
      first_day_of_week = l(:general_first_day_of_week).to_i
884
      day_of_week = Date.today.cwday
884
      day_of_week = User.current.today.cwday
885 885
      days_ago = (day_of_week >= first_day_of_week ? day_of_week - first_day_of_week : day_of_week + 7 - first_day_of_week)
886 886
      sql = relative_date_clause(db_table, db_field, - days_ago - 14, - days_ago - 1, is_custom_filter)
887 887
    when "m"
888 888
      # = this month
889
      date = Date.today
889
      date = User.current.today
890 890
      sql = date_clause(db_table, db_field, date.beginning_of_month, date.end_of_month, is_custom_filter)
891 891
    when "lm"
892 892
      # = last month
893
      date = Date.today.prev_month
893
      date = User.current.today.prev_month
894 894
      sql = date_clause(db_table, db_field, date.beginning_of_month, date.end_of_month, is_custom_filter)
895 895
    when "y"
896 896
      # = this year
897
      date = Date.today
897
      date = User.current.today
898 898
      sql = date_clause(db_table, db_field, date.beginning_of_year, date.end_of_year, is_custom_filter)
899 899
    when "~"
900 900
      sql = sql_contains("#{db_table}.#{db_field}", value.first)
......
994 994

  
995 995
  # Returns a SQL clause for a date or datetime field using relative dates.
996 996
  def relative_date_clause(table, field, days_from, days_to, is_custom_filter)
997
    date_clause(table, field, (days_from ? Date.today + days_from : nil), (days_to ? Date.today + days_to : nil), is_custom_filter)
997
    date_clause(table, field, (days_from ? User.current.today + days_from : nil), (days_to ? User.current.today + days_to : nil), is_custom_filter)
998 998
  end
999 999

  
1000 1000
  # Returns a Date or Time from the given filter value
app/models/user.rb
510 510
    if time_zone.nil?
511 511
      Date.today
512 512
    else
513
      # TODO replace with time_zone.today
513 514
      Time.now.in_time_zone(time_zone).to_date
514 515
    end
515 516
  end
app/models/version.rb
104 104

  
105 105
  # Returns true if the version is completed: closed or due date reached and no open issues
106 106
  def completed?
107
    closed? || (effective_date && (effective_date < Date.today) && (open_issues_count == 0))
107
    closed? || (effective_date && (effective_date < User.current.today) && (open_issues_count == 0))
108 108
  end
109 109

  
110 110
  def behind_schedule?
......
112 112
      return false
113 113
    elsif due_date && start_date
114 114
      done_date = start_date + ((due_date - start_date+1)* completed_percent/100).floor
115
      return done_date <= Date.today
115
      return done_date <= User.current.today
116 116
    else
117 117
      false # No issues so it's not late
118 118
    end
......
141 141

  
142 142
  # Returns true if the version is overdue: due date reached and some open issues
143 143
  def overdue?
144
    effective_date && (effective_date < Date.today) && (open_issues_count > 0)
144
    effective_date && (effective_date < User.current.today) && (open_issues_count > 0)
145 145
  end
146 146

  
147 147
  # Returns assigned issues count
app/views/activities/index.html.erb
31 31
<%= link_to_content_update(l(:label_next) + " \xc2\xbb",
32 32
                   params.merge(:from => @date_to + @days - 1),
33 33
                   :title => l(:label_date_from_to, :start => format_date(@date_to), :end => format_date(@date_to + @days - 1)),
34
                   :accesskey => accesskey(:next)) unless @date_to >= Date.today %>
34
                   :accesskey => accesskey(:next)) unless @date_to >= User.current.today %>
35 35
</div>
36 36
&nbsp;
37 37
<% other_formats_links do |f| %>
app/views/common/_calendar.html.erb
7 7
<% day = calendar.startdt
8 8
while day <= calendar.enddt %>
9 9
<%= ("<td class='week-number' title='#{ l(:label_week) }'>#{(day+(11-day.cwday)%7).cweek}</td>".html_safe) if day.cwday == calendar.first_wday %>
10
<td class="<%= day.month==calendar.month ? 'even' : 'odd' %><%= ' today' if Date.today == day %>">
10
<td class="<%= day.month==calendar.month ? 'even' : 'odd' %><%= ' today' if User.current.today == day %>">
11 11
<p class="day-num"><%= day.day %></p>
12 12
<% calendar.events_on(day).each do |i| %>
13 13
  <% if i.is_a? Issue %>
app/views/gantts/show.html.erb
302 302
<%= @gantt.lines.html_safe %>
303 303

  
304 304
<% ###### Today red line (excluded from cache) ###### %>
305
<% if Date.today >= @gantt.date_from and Date.today <= @gantt.date_to %>
305
<% if User.current.today >= @gantt.date_from and User.current.today <= @gantt.date_to %>
306 306
  <%
307
    today_left = (((Date.today - @gantt.date_from + 1) * zoom).floor() - 1).to_i
307
    today_left = (((User.current.today - @gantt.date_from + 1) * zoom).floor() - 1).to_i
308 308
    style  = ""
309 309
    style += "position: absolute;"
310 310
    style += "height: #{g_height}px;"
app/views/my/blocks/_calendar.html.erb
1 1
<h3><%= l(:label_calendar) %></h3>
2 2

  
3
<% calendar = Redmine::Helpers::Calendar.new(Date.today, current_language, :week)
3
<% calendar = Redmine::Helpers::Calendar.new(User.current.today, current_language, :week)
4 4
   calendar.events = calendar_items(calendar.startdt, calendar.enddt) %>
5 5

  
6 6
<%= render :partial => 'common/calendar', :locals => {:calendar => calendar } %>
app/views/my/blocks/_timelog.html.erb
29 29
<tbody>
30 30
<% entries_by_day.keys.sort.reverse.each do |day| %>
31 31
    <tr class="odd">
32
    <td><strong><%= day == Date.today ? l(:label_today).titleize : format_date(day) %></strong></td>
32
    <td><strong><%= day == User.current.today ? l(:label_today).titleize : format_date(day) %></strong></td>
33 33
    <td colspan="2"></td>
34 34
    <td class="hours"><em><%= html_hours("%.2f" % entries_by_day[day].sum(&:hours).to_f) %></em></td>
35 35
    <td></td>
lib/redmine/export/pdf/issues_pdf_helper.rb
26 26
          pdf = ITCPDF.new(current_language)
27 27
          pdf.set_title("#{issue.project} - #{issue.tracker} ##{issue.id}")
28 28
          pdf.alias_nb_pages
29
          pdf.footer_date = format_date(Date.today)
29
          pdf.footer_date = format_date(User.current.today)
30 30
          pdf.add_page
31 31
          pdf.SetFontStyle('B',11)
32 32
          buf = "#{issue.project} - #{issue.tracker} ##{issue.id}"
......
246 246
          title = "#{project} - #{title}" if project
247 247
          pdf.set_title(title)
248 248
          pdf.alias_nb_pages
249
          pdf.footer_date = format_date(Date.today)
249
          pdf.footer_date = format_date(User.current.today)
250 250
          pdf.set_auto_page_break(false)
251 251
          pdf.add_page("L")
252 252
  
lib/redmine/export/pdf/wiki_pdf_helper.rb
26 26
          pdf = Redmine::Export::PDF::ITCPDF.new(current_language)
27 27
          pdf.set_title(project.name)
28 28
          pdf.alias_nb_pages
29
          pdf.footer_date = format_date(Date.today)
29
          pdf.footer_date = format_date(User.current.today)
30 30
          pdf.add_page
31 31
          pdf.SetFontStyle('B',11)
32 32
          pdf.RDMMultiCell(190,5, project.name)
......
43 43
          pdf = ITCPDF.new(current_language)
44 44
          pdf.set_title("#{project} - #{page.title}")
45 45
          pdf.alias_nb_pages
46
          pdf.footer_date = format_date(Date.today)
46
          pdf.footer_date = format_date(User.current.today)
47 47
          pdf.add_page
48 48
          pdf.SetFontStyle('B',11)
49 49
          pdf.RDMMultiCell(190,5,
lib/redmine/helpers/gantt.rb
59 59
            @month_from = 1
60 60
          end
61 61
        else
62
          @month_from ||= Date.today.month
63
          @year_from ||= Date.today.year
62
          @month_from ||= User.current.today.month
63
          @year_from ||= User.current.today.year
64 64
        end
65 65
        zoom = (options[:zoom] || User.current.pref[:gantt_zoom]).to_i
66 66
        @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
......
428 428
        lines(:image => gc, :top => top, :zoom => zoom,
429 429
              :subject_width => subject_width, :format => :image)
430 430
        # today red line
431
        if Date.today >= @date_from and Date.today <= date_to
431
        if User.current.today >= @date_from and User.current.today <= date_to
432 432
          gc.stroke('red')
433
          x = (Date.today - @date_from + 1) * zoom + subject_width
433
          x = (User.current.today - @date_from + 1) * zoom + subject_width
434 434
          gc.line(x, headers_height, x, headers_height + g_height - 1)
435 435
        end
436 436
        gc.draw(imgl)
......
442 442
        pdf = ::Redmine::Export::PDF::ITCPDF.new(current_language)
443 443
        pdf.SetTitle("#{l(:label_gantt)} #{project}")
444 444
        pdf.alias_nb_pages
445
        pdf.footer_date = format_date(Date.today)
445
        pdf.footer_date = format_date(User.current.today)
446 446
        pdf.AddPage("L")
447 447
        pdf.SetFontStyle('B', 12)
448 448
        pdf.SetX(15)
......
592 592
                coords[:bar_progress_end] = self.date_to - self.date_from + 1
593 593
              end
594 594
            end
595
            if progress_date < Date.today
596
              late_date = [Date.today, end_date].min
595
            if progress_date < User.current.today
596
              late_date = [User.current.today, end_date].min
597 597
              if late_date > self.date_from && late_date > start_date
598 598
                if late_date < self.date_to
599 599
                  coords[:bar_late_end] = late_date - self.date_from + 1
lib/redmine/helpers/time_report.rb
70 70
          end
71 71
          
72 72
          min = @hours.collect {|row| row['spent_on']}.min
73
          @from = min ? min.to_date : Date.today
73
          @from = min ? min.to_date : User.current.today
74 74

  
75 75
          max = @hours.collect {|row| row['spent_on']}.max
76
          @to = max ? max.to_date : Date.today
76
          @to = max ? max.to_date : User.current.today
77 77
          
78 78
          @total_hours = @hours.inject(0) {|s,k| s = s + k['hours'].to_f}
79 79

  
test/unit/issue_test.rb
2745 2745
    issue.reload.assigned_to = nil
2746 2746
    assert_equal group, issue.assigned_to_was
2747 2747
  end
2748

  
2749
  def test_issue_overdue_should_respect_user_timezone
2750
    user_in_europe = users(:users_001)
2751
    user_in_europe.pref.update_attribute :time_zone, 'UTC'
2752

  
2753
    user_in_asia = users(:users_002)
2754
    user_in_asia.pref.update_attribute :time_zone, 'Hongkong'
2755

  
2756
    issue = Issue.generate! :due_date => Date.parse('2016-03-20')
2757

  
2758
    # server time is UTC
2759
    time = Time.parse '2016-03-20 20:00 UTC'
2760
    Time.stubs(:now).returns(time)
2761
    Date.stubs(:today).returns(time.to_date)
2762

  
2763
    # for a user in the same time zone as the server the issue is not overdue
2764
    # yet
2765
    User.current = user_in_europe
2766
    assert !issue.overdue?
2767

  
2768
    # at the same time, a user in East Asia looks at the issue - it's already
2769
    # March 21st and the issue should be marked overdue
2770
    User.current = user_in_asia
2771
    assert issue.overdue?
2772

  
2773
  end
2748 2774
end
(1-1/3)