diff --git a/app/routes/k8s.py b/app/routes/k8s.py index 8f912f0..a912cce 100644 --- a/app/routes/k8s.py +++ b/app/routes/k8s.py @@ -68,15 +68,24 @@ def fetch_k8s_data_with_usage(): def calculate_time_on_duty(creation_timestamp): """ - Calculate the time on duty in hours or days from the creation timestamp. + Calculate the time on duty in hours, days, or minutes from the creation timestamp. """ now = datetime.now(timezone.utc) delta = now - creation_timestamp - # If less than a day, return hours; otherwise, return days + # If less than an hour, return minutes + if delta.days < 1 and delta.seconds < 3600: + minutes = delta.seconds // 60 + return f"{minutes} minutes" if minutes > 1 else "less than a minute" + + # If less than a day, return hours if delta.days < 1: - return f"{delta.seconds // 3600} hours" - return f"{delta.days} days" + hours = delta.seconds // 3600 + return f"{hours} hours" if hours > 1 else "1 hour" + + # Otherwise, return days + return f"{delta.days} days" if delta.days > 1 else "1 day" + def convert_memory_to_gb(memory): """