Signed-off-by: Sami Kerola <kerolasa@xxxxxx> --- sys-utils/lsipc.c | 39 ++++++++++----------------------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/sys-utils/lsipc.c b/sys-utils/lsipc.c index 195ee15..c1d4f1c 100644 --- a/sys-utils/lsipc.c +++ b/sys-utils/lsipc.c @@ -39,6 +39,7 @@ #include "xalloc.h" #include "procutils.h" #include "ipcutils.h" +#include "timestamps.h" /* * time modes @@ -427,46 +428,26 @@ static int print_table(struct lsipc_control *ctl, struct libscols_table *tb) scols_print_table(tb); return 0; } -static struct timeval now; - -static int date_is_today(time_t t) -{ - if (now.tv_sec == 0) - gettimeofday(&now, NULL); - return t / (3600 * 24) == now.tv_sec / (3600 * 24); -} - -static int date_is_thisyear(time_t t) -{ - if (now.tv_sec == 0) - gettimeofday(&now, NULL); - return t / (3600 * 24 * 365) == now.tv_sec / (3600 * 24 * 365); -} static char *make_time(int mode, time_t time) { - char *s; struct tm tm; - char buf[64] = {0}; + char buf[64] = { 0 }; + struct ul_time t = { 0 }; - localtime_r(&time, &tm); + t.tm = localtime_r(&time, &tm); + t.buf = buf; + t.bufsz = sizeof(buf); - switch(mode) { + switch (mode) { case TIME_FULL: - asctime_r(&tm, buf); - if (*(s = buf + strlen(buf) - 1) == '\n') - *s = '\0'; + ul_timestamp_ctime_full(&t); break; case TIME_SHORT: - if (date_is_today(time)) - strftime(buf, sizeof(buf), "%H:%M", &tm); - else if (date_is_thisyear(time)) - strftime(buf, sizeof(buf), "%b%d", &tm); - else - strftime(buf, sizeof(buf), "%Y-%b%d", &tm); + ul_timestamp_ctime_short(&t); break; case TIME_ISO: - strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S%z", &tm); + ul_timestamp_iso_full(&t); break; default: errx(EXIT_FAILURE, _("unsupported time type")); -- 2.8.2 -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html