From 5bfa8329d287d6c55e594094946a26255d9761a8 Mon Sep 17 00:00:00 2001 From: Avishkar Patil Date: Sat, 5 Jun 2021 11:57:21 +0530 Subject: [PATCH] Initial Commit --- WebStreamer/utils/time_format.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 WebStreamer/utils/time_format.py diff --git a/WebStreamer/utils/time_format.py b/WebStreamer/utils/time_format.py new file mode 100644 index 00000000..0bd77903 --- /dev/null +++ b/WebStreamer/utils/time_format.py @@ -0,0 +1,24 @@ +# Bot Uptime + +def get_readable_time(seconds: int) -> str: + count = 0 + readable_time = "" + time_list = [] + time_suffix_list = ["s", "m", "h", " days"] + while count < 4: + count += 1 + if count < 3: + remainder, result = divmod(seconds, 60) + else: + remainder, result = divmod(seconds, 24) + if seconds == 0 and remainder == 0: + break + time_list.append(int(result)) + seconds = int(remainder) + for x in range(len(time_list)): + time_list[x] = str(time_list[x]) + time_suffix_list[x] + if len(time_list) == 4: + readable_time += time_list.pop() + ", " + time_list.reverse() + readable_time += ": ".join(time_list) + return readable_time