return __pakfire_strftime(buffer, length, format, t);
}
+#pragma GCC diagnostic pop
int __pakfire_format_time(char* buffer, const size_t length, const time_t t) {
const char* format = NULL;
if (t < 0)
return -EINVAL;
- if (t >= 86400)
- format = "%dd%Hh%Mm";
- else if (t >= 3600)
- format = "%Hh%Mm%Ss";
- else if (t >= 60)
- format = "%Mm%Ss";
+ int d = t / 86400;
+ int h = t % 86400 / 3600;
+ int m = t % 3600 / 60;
+ int s = t % 60;
+
+ if (d)
+ return __pakfire_string_format(buffer, length, "%dd%dh%dm", d, h, m);
+ else if (h)
+ return __pakfire_string_format(buffer, length, "%dh%dm%ds", h, m, s);
+ else if (m)
+ return __pakfire_string_format(buffer, length, "%dm%ds", m, s);
else
- format = "%Ss";
-
- return __pakfire_strftime(buffer, length, format, t);
+ return __pakfire_string_format(buffer, length, "%ds", s);
}
-#pragma GCC diagnostic pop
int __pakfire_timeval_to_iso8601(char* buffer, const size_t length, const struct timeval* t) {
struct tm tm = {};