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