Module: Flare::Util::Conversion

Overview

Description

Instance Method Summary collapse

Instance Method Details

#short_desc_of_second(second) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/flare/util/conversion.rb', line 14

def short_desc_of_second(second)
  minute = hour = day = nil
  second, unit = second.to_i, "s"
  minute, second, unit = (second/60), (second%60), "m" unless second < 60
  hour, minute, unit = (minute/60), (minute%60), "h" unless minute.nil? || minute < 60
  day, hour, unit = (hour/24), (hour%24), "d" unless hour.nil? || hour < 24
  n = (day || hour || minute || second)
  "#{n}#{unit}"
end