19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/configmonkey_cli/helper.rb', line 19
def human_seconds secs
secs = secs.to_i
t_minute = 60
t_hour = t_minute * 60
t_day = t_hour * 24
t_week = t_day * 7
t_month = t_day * 30
t_year = t_month * 12
"".tap do |r|
if secs >= t_year
r << "#{secs / t_year}y "
secs = secs % t_year
end
if secs >= t_month
r << "#{secs / t_month}m "
secs = secs % t_month
end
if secs >= t_week
r << "#{secs / t_week}w "
secs = secs % t_week
end
if secs >= t_day || !r.blank?
r << "#{secs / t_day}d "
secs = secs % t_day
end
if secs >= t_hour || !r.blank?
r << "#{secs / t_hour}h "
secs = secs % t_hour
end
if secs >= t_minute || !r.blank?
r << "#{secs / t_minute}m "
secs = secs % t_minute
end
r << "#{secs}s" unless r.include?("d")
end.strip
end
|