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