summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--service.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/service.c b/service.c
index 5f817bf..4aaad54 100644
--- a/service.c
+++ b/service.c
@@ -127,18 +127,22 @@ void serviceDrop(size_t index) {
 	services.ptr[index] = services.ptr[--services.len];
 }
 
-static const char *humanize(struct timespec uptime) {
+static const char *humanize(struct timespec interval) {
 	static char buf[256];
-	int days = uptime.tv_sec / (24 * 60 * 60);
-	uptime.tv_sec %= (24 * 60 * 60);
-	int hours = uptime.tv_sec / (60 * 60);
-	uptime.tv_sec %= (60 * 60);
-	int mins = uptime.tv_sec / 60;
-	uptime.tv_sec %= 60;
+	if (!interval.tv_sec) {
+		snprintf(buf, sizeof(buf), "%dms", (int)(interval.tv_nsec / 1000000));
+		return buf;
+	}
+	int days = interval.tv_sec / (24 * 60 * 60);
+	interval.tv_sec %= (24 * 60 * 60);
+	int hours = interval.tv_sec / (60 * 60);
+	interval.tv_sec %= (60 * 60);
+	int mins = interval.tv_sec / 60;
+	interval.tv_sec %= 60;
 	int d, h, m, s;
 	snprintf(
 		buf, sizeof(buf), "%n%dd %n%dh %n%dm %n%ds",
-		&d, days, &h, hours, &m, mins, &s, (int)uptime.tv_sec
+		&d, days, &h, hours, &m, mins, &s, (int)interval.tv_sec
 	);
 	if (days) return &buf[d];
 	if (hours) return &buf[h];