From ad53ba06319bbbd625a43090e37dffc3ea825f2a Mon Sep 17 00:00:00 2001 From: jesopo Date: Thu, 9 Aug 2018 12:23:54 +0100 Subject: Added Utils.to_pretty_time --- Utils.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Utils.py b/Utils.py index 1e0e90b3..eca0e895 100644 --- a/Utils.py +++ b/Utils.py @@ -175,6 +175,25 @@ def from_pretty_time(pretty_time): if seconds > 0: return seconds +def to_pretty_time(total_seconds): + minutes, seconds = divmod(total_seconds, 60) + hours, minutes = divmod(minutes, 60) + days, hours = divmod(hours, 24) + weeks, days = divmod(days, 7) + out = "" + + if not weeks == 0: + out += "%dw" % weeks + if not days == 0: + out += "%dd" % days + if not hours == 0: + out += "%dh" % hours + if not minutes == 0: + out += "%dm" % minutes + if not seconds == 0: + out += "%ds" % seconds + return out + IS_TRUE = ["true", "yes", "on", "y"] IS_FALSE = ["false", "no", "off", "n"] def bool_or_none(s): -- cgit v1.3.1-10-gc9f91