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