Add some __doc__ to the parse from/to str/secs methods
This commit is contained in:
parent
c83cdb6b4a
commit
6ef488ae80
1 changed files with 11 additions and 0 deletions
|
@ -194,6 +194,11 @@ def replace_key_with_bound(key):
|
||||||
return key
|
return key
|
||||||
|
|
||||||
def parse_str_to_secs(duration=''):
|
def parse_str_to_secs(duration=''):
|
||||||
|
"""
|
||||||
|
Parse a string of with a number of d, h, m, s
|
||||||
|
>>> parse_str_to_secs("1d3m1h")
|
||||||
|
90180
|
||||||
|
"""
|
||||||
values = {'s': 1, 'm': 60, 'h': 3600, 'd': 86400}
|
values = {'s': 1, 'm': 60, 'h': 3600, 'd': 86400}
|
||||||
result = 0
|
result = 0
|
||||||
tmp = '0'
|
tmp = '0'
|
||||||
|
@ -211,6 +216,12 @@ def parse_str_to_secs(duration=''):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def parse_secs_to_str(duration=0):
|
def parse_secs_to_str(duration=0):
|
||||||
|
"""
|
||||||
|
Parse a number of seconds to a human-readable string.
|
||||||
|
The string has the form XdXhXmXs. 0 units are removed.
|
||||||
|
>>> parse_secs_to_str(3601)
|
||||||
|
1h1s
|
||||||
|
"""
|
||||||
secs, mins, hours, days = 0, 0, 0, 0
|
secs, mins, hours, days = 0, 0, 0, 0
|
||||||
result = ''
|
result = ''
|
||||||
secs = duration % 60
|
secs = duration % 60
|
||||||
|
|
Loading…
Reference in a new issue