]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Refactor the date formatting slightly.
authorTim Kientzle <kientzle@gmail.com>
Sun, 26 Jul 2009 21:42:30 +0000 (17:42 -0400)
committerTim Kientzle <kientzle@gmail.com>
Sun, 26 Jul 2009 21:42:30 +0000 (17:42 -0400)
SVN-Revision: 1280

tar/read.c

index 16709a3f767ffc8c7a08f17f5dd000a64b86dcd6..b95b0217ca81f83cae9737b0412fe3856a3e53f8 100644 (file)
@@ -416,18 +416,16 @@ list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry)
 
        /* Format the time using 'ls -l' conventions. */
        tim = archive_entry_mtime(entry);
+#define HALF_YEAR (time_t)365 * 86400 / 2
 #if defined(_WIN32) && !defined(__CYGWIN__)
-       /* Windows' strftime function does not support %e format. */
-       if (abs(tim - now) > (365/2)*86400)
-               fmt = bsdtar->day_first ? "%d %b  %Y" : "%b %d  %Y";
-       else
-               fmt = bsdtar->day_first ? "%d %b %H:%M" : "%b %d %H:%M";
+#define DAY_FMT  "%d"  /* Windows' strftime function does not support %e format. */
 #else
-       if (abs(tim - now) > (365/2)*86400)
-               fmt = bsdtar->day_first ? "%e %b  %Y" : "%b %e  %Y";
-       else
-               fmt = bsdtar->day_first ? "%e %b %H:%M" : "%b %e %H:%M";
+#define DAY_FMT  "%e"  /* Day number without leading zeros */
 #endif
+       if (tim < now - HALF_YEAR || tim > now + HALF_YEAR)
+               fmt = bsdtar->day_first ? DAY_FMT " %b  %Y" : "%b " DAY_FMT "  %Y";
+       else
+               fmt = bsdtar->day_first ? DAY_FMT " %b %H:%M" : "%b " DAY_FMT " %H:%M";
        strftime(tmp, sizeof(tmp), fmt, localtime(&tim));
        fprintf(out, " %s ", tmp);
        safe_fprintf(out, "%s", archive_entry_pathname(entry));