formatter.py 963 B

1234567891011121314151617181920212223242526272829303132
  1. def get_readable_time(seconds: int) -> str:
  2. count = 0
  3. ping_time = ""
  4. time_list = []
  5. time_suffix_list = ["s", "m", "h", "days"]
  6. while count < 4:
  7. count += 1
  8. if count < 3:
  9. remainder, result = divmod(seconds, 60)
  10. else:
  11. remainder, result = divmod(seconds, 24)
  12. if seconds == 0 and remainder == 0:
  13. break
  14. time_list.append(int(result))
  15. seconds = int(remainder)
  16. for i in range(len(time_list)):
  17. time_list[i] = str(time_list[i]) + time_suffix_list[i]
  18. if len(time_list) == 4:
  19. ping_time += time_list.pop() + ", "
  20. time_list.reverse()
  21. ping_time += ":".join(time_list)
  22. return ping_time
  23. # Convert seconds to mm:ss
  24. async def convert_seconds_to_minutes(seconds: int):
  25. seconds = int(seconds)
  26. seconds = seconds % (24 * 3600)
  27. seconds %= 3600
  28. minutes = seconds // 60
  29. seconds %= 60
  30. return "%02d:%02d" % (minutes, seconds)