Skip to content

Commit

Permalink
seconds2human is now able to handle type string
Browse files Browse the repository at this point in the history
  • Loading branch information
markuslf committed Feb 25, 2020
1 parent ace23cc commit 68ce420
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions output.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# https://nagios-plugins.org/doc/guidelines.html

__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
__version__ = '2020021701'
__version__ = '2020022501'

from .globals import *

Expand Down Expand Up @@ -58,21 +58,23 @@ def unix_time_to_iso(timestamp):


def seconds2human(seconds, full_name=False):

seconds = int(seconds)
if full_name:
intervals = (
('weeks', 604800), # 60 * 60 * 24 * 7
('days', 86400), # 60 * 60 * 24
('hours', 3600), # 60 * 60
('minutes', 60),
('seconds', 1),
('weeks', 604800), # 60 * 60 * 24 * 7
('days', 86400), # 60 * 60 * 24
('hours', 3600), # 60 * 60
('minutes', 60),
('seconds', 1),
)
else:
intervals = (
('w', 604800), # 60 * 60 * 24 * 7
('d', 86400), # 60 * 60 * 24
('h', 3600), # 60 * 60
('m', 60),
('s', 1),
('w', 604800), # 60 * 60 * 24 * 7
('d', 86400), # 60 * 60 * 24
('h', 3600), # 60 * 60
('m', 60),
('s', 1),
)

result = []
Expand All @@ -82,7 +84,7 @@ def seconds2human(seconds, full_name=False):
if value:
seconds -= value * count
if full_name and value == 1:
name = name.rstrip('s') # days -> day
name = name.rstrip('s') # "days" becomes "day"
result.append('{:.0f}{}'.format(value, name))
return ' '.join(result)

Expand Down

0 comments on commit 68ce420

Please sign in to comment.