4: def self.distance_of_time_in_words(from_time, to_time = 0, include_seconds = false, absolute = false)
5: from_time = from_time.to_time if from_time.respond_to?(:to_time)
6: to_time = to_time.to_time if to_time.respond_to?(:to_time)
7: distance_in_minutes = (((to_time - from_time).abs)/60).round
8: distance_in_seconds = ((to_time - from_time).abs).round
9:
10: case distance_in_minutes
11: when 0..1
12: return (distance_in_minutes==0) ? 'меньше минуты' : '1 минуту' unless include_seconds
13:
14: case distance_in_seconds
15: when 0..5 then 'менее 5 секунд'
16: when 6..10 then 'менее 10 секунд'
17: when 11..20 then 'менее 20 секунд'
18: when 21..40 then 'пол-минуты'
19: when 41..59 then 'меньше минуты'
20: else '1 минуту'
21: end
22:
23: when 2..45 then distance_in_minutes.to_s +
24: " " + distance_in_minutes.items("минута", "минуты", "минут")
25: when 46..90 then 'около часа'
26:
27: when 90..1440 then "около " + (distance_in_minutes.to_f / 60.0).round.to_s +
28: " " + (distance_in_minutes.to_f / 60.0).round.items("часа", 'часов', 'часов')
29: when 1441..2880 then '1 день'
30: else (distance_in_minutes / 1440).round.to_s +
31: " " + (distance_in_minutes / 1440).round.items("день", "дня", "дней")
32: end
33: end