From e31f04d062aa9b6ff7f94af70c0978f31d946b1a Mon Sep 17 00:00:00 2001 From: Jay Knight Date: Tue, 22 Jul 2025 16:04:22 -0500 Subject: [PATCH] Don't include '.0' on minutes and hours for durations when passed as large floats. --- AUTHORS | 1 + changelog.rst | 5 +++++ pgcli/main.py | 4 ++-- tests/test_main.py | 2 ++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index 40d7f586..d62e13d2 100644 --- a/AUTHORS +++ b/AUTHORS @@ -141,6 +141,7 @@ Contributors: * Josh Lynch (josh-lynch) * Fabio (3ximus) * Doug Harris (dougharris) + * Jay Knight (jay-knight) Creator: -------- diff --git a/changelog.rst b/changelog.rst index 8cab8c15..10d69d1a 100644 --- a/changelog.rst +++ b/changelog.rst @@ -17,6 +17,11 @@ Internal: * Update dev requirements and replace requirements-dev.txt with pyproject.toml * Use ruff instead of black +Bug fixes: +---------- + +* Improve display of larger durations when passed as floats + 4.3.0 (2025-03-22) ================== diff --git a/pgcli/main.py b/pgcli/main.py index 61bc277b..5edfb909 100644 --- a/pgcli/main.py +++ b/pgcli/main.py @@ -1926,12 +1926,12 @@ def duration_in_words(duration_in_seconds: float) -> str: components = [] hours, remainder = divmod(duration_in_seconds, 3600) if hours > 1: - components.append(f"{hours} hours") + components.append(f"{int(hours)} hours") elif hours == 1: components.append("1 hour") minutes, seconds = divmod(remainder, 60) if minutes > 1: - components.append(f"{minutes} minutes") + components.append(f"{int(minutes)} minutes") elif minutes == 1: components.append("1 minute") if seconds >= 2: diff --git a/tests/test_main.py b/tests/test_main.py index b893d2c9..5cf1d09f 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -565,9 +565,11 @@ def test_application_name_db_uri(tmpdir): (60, "1 minute"), (61, "1 minute 1 second"), (123, "2 minutes 3 seconds"), + (124.4, "2 minutes 4 seconds"), (3600, "1 hour"), (7235, "2 hours 35 seconds"), (9005, "2 hours 30 minutes 5 seconds"), + (9006.7, "2 hours 30 minutes 6 seconds"), (86401, "24 hours 1 second"), ], )