diff options
author | VAN BOSSUYT Nicolas <nicolas.van.bossuyt@gmail.com> | 2019-04-14 19:10:24 +0200 |
---|---|---|
committer | VAN BOSSUYT Nicolas <nicolas.van.bossuyt@gmail.com> | 2019-04-14 19:10:24 +0200 |
commit | 12f2d1f2e89780cec2ebdfcf35fc8970087012e0 (patch) | |
tree | 114d1a207fb76cd8a950e0de6988427881fe51bf /Userland | |
parent | c0fe48635b94d30b3f431050a5f275421edfbe48 (diff) | |
download | serenity-12f2d1f2e89780cec2ebdfcf35fc8970087012e0.zip |
Uptime: making the ouput prettier
Just like the -p option on linux
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/uptime.cpp | 23 |
1 files 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); |