Project

General

Profile

Patch #25402 » distance_in_words.patch

Quick and dirty fix for future dates in 4.1.1 - Greg T, 2020-05-07 16:06

View differences:

config/initializers/10-patches.rb 2020-04-20 05:03:28.566680261 +0200
36 36
    module DateHelper
37 37
      # distance_of_time_in_words breaks when difference is greater than 30 years
38 38
      def distance_of_date_in_words(from_date, to_date = 0, options = {})
39
        options = {
40
          scope: :'datetime.distance_in_words'
41
        }.merge!(options)
39 42
        from_date = from_date.to_date if from_date.respond_to?(:to_date)
40 43
        to_date = to_date.to_date if to_date.respond_to?(:to_date)
41 44
        distance_in_days = (to_date - from_date).abs
42 45

  
43
        I18n.with_options :locale => options[:locale], :scope => :'datetime.distance_in_words' do |locale|
46
        I18n.with_options :locale => options[:locale], :scope => options[:scope] do |locale|
44 47
          case distance_in_days
45 48
            when 0..60     then locale.t :x_days,             :count => distance_in_days.round
46 49
            when 61..720   then locale.t :about_x_months,     :count => (distance_in_days / 30).round
47
-- app/helpers/application_helper.rb.orig	2020-04-06 19:00:46.000000000 +0200
50
++ app/helpers/application_helper.rb	2020-04-20 04:50:30.907386933 +0200
......
362 362

  
363 363
  def due_date_distance_in_words(date)
364 364
    if date
365
      l((date < User.current.today ? :label_roadmap_overdue : :label_roadmap_due_in), distance_of_date_in_words(User.current.today, date))
365
      if date < User.current.today
366
        l(:label_roadmap_overdue, distance_of_date_in_words(User.current.today, date))
367
      else
368
        l(:label_roadmap_due_in,  distance_of_date_in_words(User.current.today, date, scope: :'datetime'))
369
      end
366 370
    end
367 371
  end
368 372

  
(2-2/2)