From 68ce42052ca66ecdb96ecc97558eed41efef7faf Mon Sep 17 00:00:00 2001 From: Markus Frei Date: Tue, 25 Feb 2020 22:01:19 +0100 Subject: [PATCH] seconds2human is now able to handle type string --- output.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/output.py b/output.py index 7062b23..b9af0f3 100644 --- a/output.py +++ b/output.py @@ -9,7 +9,7 @@ # https://nagios-plugins.org/doc/guidelines.html __author__ = 'Linuxfabrik GmbH, Zurich/Switzerland' -__version__ = '2020021701' +__version__ = '2020022501' from .globals import * @@ -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 = [] @@ -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)