From 12f2d1f2e89780cec2ebdfcf35fc8970087012e0 Mon Sep 17 00:00:00 2001 From: VAN BOSSUYT Nicolas Date: Sun, 14 Apr 2019 19:10:24 +0200 Subject: [PATCH] Uptime: making the ouput prettier Just like the -p option on linux --- Userland/uptime.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/Userland/uptime.cpp b/Userland/uptime.cpp index fc0b852bfa..4ee6717f6a 100644 --- a/Userland/uptime.cpp +++ b/Userland/uptime.cpp @@ -18,12 +18,23 @@ int main(int, char**) unsigned seconds; sscanf(buffer, "%u", &seconds); - printf("Up %d day%s, ", seconds / 86400, (seconds / 86400) == 1 ? "" : "s"); - seconds %= 86400; - printf("%d hour%s, ", seconds / 3600, (seconds / 3600) == 1 ? "" : "s"); - seconds %= 3600; - printf("%d minute%s, ", seconds / 60, (seconds / 60) == 1 ? "" : "s"); - seconds %= 60; + printf("Up "); + + if (seconds / 86400 > 0) { + printf("%d day%s, ", seconds / 86400, (seconds / 86400) == 1 ? "" : "s"); + seconds %= 86400; + } + + if (seconds / 3600 > 0) { + printf("%d hour%s, ", seconds / 3600, (seconds / 3600) == 1 ? "" : "s"); + seconds %= 3600; + } + + if (seconds / 60 > 0) { + printf("%d minute%s, ", seconds / 60, (seconds / 60) == 1 ? "" : "s"); + seconds %= 60; + } + printf("%d second%s\n", seconds, seconds == 1 ? "" : "s"); fclose(fp);