]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsipc: use strtime_short()
authorKarel Zak <kzak@redhat.com>
Tue, 24 May 2016 11:22:40 +0000 (13:22 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 24 May 2016 11:22:40 +0000 (13:22 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/lsipc.c

index 6e01f47ace5a4841a2918d9263984dad5e1df23d..9041dc17b9b31f7cd626b9a7ecb6c96a133b4649 100644 (file)
@@ -430,44 +430,27 @@ static int print_table(struct lsipc_control *ctl, struct libscols_table *tb)
 }
 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};
 
-       localtime_r(&time, &tm);
-
        switch(mode) {
        case TIME_FULL:
+       {
+               struct tm tm;
+               char *s;
+
+               localtime_r(&time, &tm);
                asctime_r(&tm, buf);
                if (*(s = buf + strlen(buf) - 1) == '\n')
                        *s = '\0';
                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);
+               strtime_short(&time, &now, 0, buf, sizeof(buf));
                break;
        case TIME_ISO:
-               strtm_iso(&tm, ISO_8601_DATE|ISO_8601_TIME|ISO_8601_TIMEZONE, buf, sizeof(buf));
+               strtime_iso(&time, ISO_8601_DATE|ISO_8601_TIME|ISO_8601_TIMEZONE, buf, sizeof(buf));
                break;
        default:
                errx(EXIT_FAILURE, _("unsupported time type"));