Skip to content
This repository was archived by the owner on Sep 29, 2021. It is now read-only.

Commit a0b85f5

Browse files
authored
Create timefunc.py
1 parent 55f6b30 commit a0b85f5

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

userbot/modules/timefunc.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import time
2+
3+
uptimebot = time.time()
4+
5+
6+
def get_readable_time(seconds: int) -> str:
7+
count = 0
8+
ping_time = ""
9+
time_list = []
10+
time_suffix_list = ["s", "m", "h", "days"]
11+
12+
while count < 4:
13+
count += 1
14+
if count < 3:
15+
remainder, result = divmod(seconds, 60)
16+
else:
17+
remainder, result = divmod(seconds, 24)
18+
if seconds == 0 and remainder == 0:
19+
break
20+
time_list.append(int(result))
21+
seconds = int(remainder)
22+
23+
for x in range(len(time_list)):
24+
time_list[x] = str(time_list[x]) + time_suffix_list[x]
25+
if len(time_list) == 4:
26+
ping_time += time_list.pop() + ", "
27+
28+
time_list.reverse()
29+
ping_time += ":".join(time_list)
30+
31+
return ping_time

0 commit comments

Comments
 (0)