15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/uffizzi/date_helper.rb', line 15
def count_distanse(now, previous_date)
seconds = (now - previous_date).round
return convert_to_words(seconds, 'seconds') if seconds < TWO_MINUTES
minutes = seconds / 60
return convert_to_words(minutes, 'minutes') if minutes < TWO_HOURS
hours = minutes / 60
return convert_to_words(hours, 'hours') if hours < TWO_DAYS
days = hours / 24
return convert_to_words(days, 'days') if days < TWO_WEEKS
weeks = days / 7
return convert_to_words(weeks, 'weeks') if days < TWO_MONTHS
months = (days / (365 / 12)).round
return convert_to_words(months, 'months') if days < TWO_YEARS
years = days / 365
convert_to_words(years, 'years')
end
|