diff options
| author | 2018-08-09 12:23:54 +0100 | |
|---|---|---|
| committer | 2018-08-09 12:23:54 +0100 | |
| commit | ad53ba06319bbbd625a43090e37dffc3ea825f2a (patch) | |
| tree | 5255493a595358da74d8c9b776f0939a8f3792a3 /Utils.py | |
| parent | Switch to using monotonic time in Database.py timing (diff) | |
| signature | ||
Added Utils.to_pretty_time
Diffstat (limited to 'Utils.py')
| -rw-r--r-- | Utils.py | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -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): |
