340a94
From 7eade2544e1c45bc516744aeaccc45df1d8f42df Mon Sep 17 00:00:00 2001
340a94
From: Kyle Walker <kwalker@redhat.com>
340a94
Date: Tue, 11 Feb 2020 14:30:39 -0500
340a94
Subject: [PATCH] whattime: Refactor the pretty-print evaluation
340a94
340a94
This avoids rounding errors such as in the case of 364 days of uptime which
340a94
results in only output that prints at the hour and below.
340a94
---
340a94
 proc/whattime.c | 15 ++++++++++++---
340a94
 1 file changed, 12 insertions(+), 3 deletions(-)
340a94
340a94
diff --git a/proc/whattime.c b/proc/whattime.c
340a94
index c223cad..3e1b65c 100644
340a94
--- a/proc/whattime.c
340a94
+++ b/proc/whattime.c
340a94
@@ -69,9 +69,18 @@ char *sprint_uptime(int human_readable) {
340a94
 
340a94
   if (human_readable) {
340a94
     updecades = (int) uptime_secs / (60*60*24*365*10);
340a94
-    upyears = ((int) uptime_secs / (60*60*24*365)) % 10;
340a94
-    upweeks = ((int) uptime_secs / (60*60*24*7)) % 52;
340a94
-    updays = ((int) uptime_secs / (60*60*24)) % 7;
340a94
+    if (updecades)
340a94
+        uptime_secs -= updecades * (60*60*24*365*10);
340a94
+
340a94
+    upyears = (int) uptime_secs / (60*60*24*365);
340a94
+    if (upyears)
340a94
+        uptime_secs -= upyears * (60*60*24*365);
340a94
+
340a94
+    upweeks = (int) uptime_secs / (60*60*24*7);
340a94
+    if (upweeks)
340a94
+        uptime_secs -= upweeks * (60*60*24*7);
340a94
+
340a94
+    updays = (int) uptime_secs / (60*60*24);
340a94
   }
340a94
   else
340a94
     updays = (int) uptime_secs / (60*60*24);
340a94
-- 
340a94
2.24.1
340a94