Module: Uffizzi::DateHelper

Defined in:
lib/uffizzi/date_helper.rb

Constant Summary collapse

TWO_MINUTES =
120
TWO_HOURS =
120
TWO_DAYS =
48
TWO_WEEKS =
14
TWO_MONTHS =
(365 / 12 * 2)
TWO_YEARS =
730

Class Method Summary collapse

Class Method Details

.count_distanse(now, previous_date) ⇒ Object



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