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
module DateHelper
# distance_of_time_in_words breaks when difference is greater than 30 years
def distance_of_date_in_words(from_date, to_date = 0, options = {})
options = {
scope: :'datetime.distance_in_words'
}.merge!(options)
from_date = from_date.to_date if from_date.respond_to?(:to_date)
to_date = to_date.to_date if to_date.respond_to?(:to_date)
distance_in_days = (to_date - from_date).abs
I18n.with_options :locale => options[:locale], :scope => :'datetime.distance_in_words' do |locale|
I18n.with_options :locale => options[:locale], :scope => options[:scope] do |locale|
case distance_in_days
when 0..60 then locale.t :x_days, :count => distance_in_days.round
when 61..720 then locale.t :about_x_months, :count => (distance_in_days / 30).round
-- app/helpers/application_helper.rb.orig 2020-04-06 19:00:46.000000000 +0200
++ app/helpers/application_helper.rb 2020-04-20 04:50:30.907386933 +0200
......
def due_date_distance_in_words(date)
if date
l((date < User.current.today ? :label_roadmap_overdue : :label_roadmap_due_in), distance_of_date_in_words(User.current.today, date))
if date < User.current.today
l(:label_roadmap_overdue, distance_of_date_in_words(User.current.today, date))
else
l(:label_roadmap_due_in, distance_of_date_in_words(User.current.today, date, scope: :'datetime'))
end
end
end
(2-2/2)