|
11 | 11 | import threading |
12 | 12 | import shutil |
13 | 13 | import functools |
14 | | -import pendulum |
15 | 14 | import datetime as dt |
16 | 15 | import itertools |
17 | 16 | import platform |
@@ -800,9 +799,9 @@ def execute_command(self, text, handle_closed_connection=True): |
800 | 799 | "Time: %0.03fs (%s), executed in: %0.03fs (%s)" |
801 | 800 | % ( |
802 | 801 | query.total_time, |
803 | | - pendulum.Duration(seconds=query.total_time).in_words(), |
| 802 | + duration_in_words(query.total_time), |
804 | 803 | query.execution_time, |
805 | | - pendulum.Duration(seconds=query.execution_time).in_words(), |
| 804 | + duration_in_words(query.execution_time), |
806 | 805 | ) |
807 | 806 | ) |
808 | 807 | else: |
@@ -1735,5 +1734,28 @@ def parse_service_info(service): |
1735 | 1734 | return service_conf, service_file |
1736 | 1735 |
|
1737 | 1736 |
|
| 1737 | +def duration_in_words(duration_in_seconds: float) -> str: |
| 1738 | + if not duration_in_seconds: |
| 1739 | + return "0 seconds" |
| 1740 | + components = [] |
| 1741 | + hours, remainder = divmod(duration_in_seconds, 3600) |
| 1742 | + if hours > 1: |
| 1743 | + components.append(f"{hours} hours") |
| 1744 | + elif hours == 1: |
| 1745 | + components.append("1 hour") |
| 1746 | + minutes, seconds = divmod(remainder, 60) |
| 1747 | + if minutes > 1: |
| 1748 | + components.append(f"{minutes} minutes") |
| 1749 | + elif minutes == 1: |
| 1750 | + components.append("1 minute") |
| 1751 | + if seconds >= 2: |
| 1752 | + components.append(f"{int(seconds)} seconds") |
| 1753 | + elif seconds >= 1: |
| 1754 | + components.append("1 second") |
| 1755 | + elif seconds: |
| 1756 | + components.append(f"{round(seconds, 3)} second") |
| 1757 | + return " ".join(components) |
| 1758 | + |
| 1759 | + |
1738 | 1760 | if __name__ == "__main__": |
1739 | 1761 | cli() |
0 commit comments