From c12a30328c4c7ea65697ec6a22c927becd1f99b3 Mon Sep 17 00:00:00 2001 From: Stefan Holst Date: Tue, 12 Jan 2021 15:18:37 +0900 Subject: [PATCH] better hr_time --- src/kyupy/__init__.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/kyupy/__init__.py b/src/kyupy/__init__.py index c197832..7e8c78d 100644 --- a/src/kyupy/__init__.py +++ b/src/kyupy/__init__.py @@ -31,15 +31,22 @@ def hr_bytes(nbytes): def hr_time(seconds): s = '' + if seconds >= 86400: + d = seconds // 86400 + seconds -= d * 86400 + s += f'{int(d)}d' if seconds >= 3600: h = seconds // 3600 seconds -= h * 3600 s += f'{int(h)}h' - if seconds >= 60 or len(s) > 0: + if seconds >= 60: m = seconds // 60 seconds -= m * 60 - s += f'{int(m)}m' - return f'{s}{int(seconds)}s' + if 'd' not in s: + s += f'{int(m)}m' + if 'h' not in s and 'd' not in s: + s += f'{int(seconds)}s' + return s class Log: