Module: Boppers::Uptime::RelativeTime

Defined in:
lib/boppers/uptime/relative_time.rb

Class Method Summary collapse

Class Method Details

.call(from_time, to_time) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/boppers/uptime/relative_time.rb', line 6

def self.call(from_time, to_time)
  seconds = (to_time - from_time).to_i
  return plural(seconds, "second") if seconds < 60

  minutes = (seconds / 60).to_i
  return plural(minutes, "minute") if minutes < 60

  hours = (minutes / 60).to_i
  return plural(hours, "hour") if hours < 24

  days = (hours / 24).to_i
  plural(days, "day")
end

.plural(count, one, many = "#{one}s") ⇒ Object



20
21
22
23
24
25
26
# File 'lib/boppers/uptime/relative_time.rb', line 20

def self.plural(count, one, many = "#{one}s")
  if count == 1
    "#{count} #{one}"
  else
    "#{count} #{many}"
  end
end