diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2023-12-25 17:50:17 +0100 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2023-12-25 17:50:17 +0100 |
commit | 274bc8b1f4b180c75714447303d922249edf8bde (patch) | |
tree | 763c2318f34d3af5c0c6494218cc00c72de49bbd | |
parent | cd60f463cc7853d84992af9dfa79a4c7c0352323 (diff) |
Reformatted hms_desc()
-rw-r--r-- | FICS/utils.c | 61 |
1 files changed, 29 insertions, 32 deletions
diff --git a/FICS/utils.c b/FICS/utils.c index 257e117..fab43fd 100644 --- a/FICS/utils.c +++ b/FICS/utils.c @@ -563,39 +563,36 @@ xstrdup(const char *str) return strcpy(out, str); } -PUBLIC char *hms_desc(int t) +PUBLIC char * +hms_desc(int t) { -static char tstr[80]; -int days, hours, mins, secs; - - days = (t / (60*60*24)); - hours = ((t % (60*60*24)) / (60*60)); - mins = (((t % (60*60*24)) % (60*60)) / 60); - secs = (((t % (60*60*24)) % (60*60)) % 60); - if ((days==0) && (hours==0) && (mins==0)) { - sprintf(tstr, "%d sec%s", - secs, (secs==1) ? "" : "s"); - } else if ((days==0) && (hours==0)) { -/* sprintf(tstr, "%d min%s, %d sec%s", - mins, (mins==1) ? "" : "s", - secs, (secs==1) ? "" : "s"); */ - sprintf(tstr, "%d min%s", - mins, (mins==1) ? "" : "s"); - } else if (days==0) { - sprintf(tstr, "%d hr%s, %d min%s, %d " - "sec%s", - hours, (hours==1) ? "" : "s", - mins, (mins==1) ? "" : "s", - secs, (secs==1) ? "" : "s"); - } else { - sprintf(tstr, "%d day%s, %d hour%s, %d minute%s " - "and %d second%s", - days, (days==1) ? "" : "s", - hours, (hours==1) ? "" : "s", - mins, (mins==1) ? "" : "s", - secs, (secs==1) ? "" : "s"); - } - return tstr; + int days, hours, mins, secs; + static char tstr[80]; + + days = t / (60 * 60 * 24); + hours = (t % (60 * 60 * 24)) / (60 * 60); + mins = ((t % (60 * 60 * 24)) % (60 * 60)) / 60; + secs = ((t % (60 * 60 * 24)) % (60 * 60)) % 60; + + if (days == 0 && hours == 0 && mins == 0) { + sprintf(tstr, "%d sec%s", secs, (secs == 1 ? "" : "s")); + } else if (days == 0 && hours == 0) { + sprintf(tstr, "%d min%s", mins, (mins == 1 ? "" : "s")); + } else if (days == 0) { + sprintf(tstr, "%d hr%s, %d min%s, %d sec%s", + hours, (hours == 1 ? "" : "s"), + mins, (mins == 1 ? "" : "s"), + secs, (secs == 1 ? "" : "s")); + } else { + sprintf(tstr, "%d day%s, %d hour%s, %d minute%s and " + "%d second%s", + days, (days == 1 ? "" : "s"), + hours, (hours == 1 ? "" : "s"), + mins, (mins == 1 ? "" : "s"), + secs, (secs == 1 ? "" : "s")); + } + + return tstr; } PUBLIC char * |