From 1ccab4064b02802dfb09f74838557f7238646b4a Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Sun, 26 Jul 2009 17:42:30 -0400 Subject: [PATCH] Refactor the date formatting slightly. SVN-Revision: 1280 --- tar/read.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tar/read.c b/tar/read.c index 16709a3f7..b95b0217c 100644 --- a/tar/read.c +++ b/tar/read.c @@ -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)); -- 2.47.3