Added Utils.to_pretty_time
This commit is contained in:
parent
f7e4d08eb0
commit
ad53ba0631
1 changed files with 19 additions and 0 deletions
19
Utils.py
19
Utils.py
|
@ -175,6 +175,25 @@ def from_pretty_time(pretty_time):
|
||||||
if seconds > 0:
|
if seconds > 0:
|
||||||
return seconds
|
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_TRUE = ["true", "yes", "on", "y"]
|
||||||
IS_FALSE = ["false", "no", "off", "n"]
|
IS_FALSE = ["false", "no", "off", "n"]
|
||||||
def bool_or_none(s):
|
def bool_or_none(s):
|
||||||
|
|
Loading…
Reference in a new issue