Skip to content

Commit c160918

Browse files
committed
Added a seconds to human-readable time convertor
1 parent 0e67a15 commit c160918

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

senpy/utils.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,26 @@ def sleep(self, seconds: int) -> None:
5858
Args:
5959
seconds (int): The number of seconds to sleep for.
6060
"""
61-
time.sleep(seconds)
61+
time.sleep(seconds)
62+
63+
def convert_seconds_to_time(self, rawseconds: int) -> str:
64+
"""
65+
Converts seconds to human readable representation.
66+
67+
Args:
68+
rawseconds (int): The number of seconds to convert.
69+
70+
Returns:
71+
str: The human readable representation of the time.
72+
"""
73+
days = rawseconds // 86400
74+
hours = (rawseconds - days * 86400) // 3600
75+
minutes = (rawseconds - days * 86400 - hours * 3600) // 60
76+
seconds = rawseconds - days * 86400 - hours * 3600 - minutes * 60
77+
78+
time = (("{0} day{1}, ".format(days, "s" if days != 1 else "") if days else "") + \
79+
("{0} hour{1}, ".format(hours, "s" if hours != 1 else "") if hours else "") + \
80+
("{0} minute{1}, ".format(minutes, "s" if minutes != 1 else "") if minutes else "") + \
81+
("{0} second{1}, ".format(seconds, "s" if seconds != 1 else "") if seconds else ""))[0:-2]
82+
83+
return time

0 commit comments

Comments
 (0)