| Module | ActionView::Helpers::DateHelper |
| In: |
brdata/lib/brdata/br_date_helper.rb
|
Traduz o método distance_of_time_in_words para retornar esse valor em português
# File brdata/lib/brdata/br_date_helper.rb, line 4
4: def distance_of_time_in_words(from_time, to_time = 0, include_seconds = 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) ? 'menos de um minuto' : '1 minuto' unless include_seconds
13: case distance_in_seconds
14: when 0..4 then 'menos de 5 segundos'
15: when 5..9 then 'menos de 10 segundos'
16: when 10..19 then 'menos de 20 segundos'
17: when 20..39 then 'meio minuto'
18: when 40..59 then 'menos de um minuto'
19: else '1 minuto'
20: end
21:
22: when 2..44 then "#{distance_in_minutes} minutos"
23: when 45..89 then 'aproximadamente 1 hora'
24: when 90..1439 then "aproximadamente #{(distance_in_minutes.to_f / 60.0).round} horas"
25: when 1440..2879 then '1 dia'
26: when 2880..43199 then "#{(distance_in_minutes / 1440).round} dias"
27: when 43200..86399 then 'aproximadamente 1 mês'
28: when 86400..525959 then "#{(distance_in_minutes / 43200).round} meses"
29: when 525960..1051919 then 'aproximadamente 1 ano'
30: else "mais de #{(distance_in_minutes / 525960).round} anos"
31: end
32: end