X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=inline;f=date.c;h=1165d30adfa783f7cbaa871e38a1370f9f9c4996;hb=ea0b767c1ea66f687e58a9fcff45a5a518e699c3;hp=d75dff42405404ec86820a534620c1ba68cd9116;hpb=4e286ece2ee8d6f486faaa522f1de5c363a9a765;p=git.git diff --git a/date.c b/date.c index d75dff424..1165d30ad 100644 --- a/date.c +++ b/date.c @@ -133,7 +133,25 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode) snprintf(timebuf, sizeof(timebuf), "%lu months ago", (diff + 15) / 30); return timebuf; } - /* Else fall back on absolute format.. */ + /* Give years and months for 5 years or so */ + if (diff < 1825) { + unsigned long years = (diff + 183) / 365; + unsigned long months = (diff % 365 + 15) / 30; + int n; + n = snprintf(timebuf, sizeof(timebuf), "%lu year%s", + years, (years > 1 ? "s" : "")); + if (months) + snprintf(timebuf + n, sizeof(timebuf) - n, + ", %lu month%s ago", + months, (months > 1 ? "s" : "")); + else + snprintf(timebuf + n, sizeof(timebuf) - n, + " ago"); + return timebuf; + } + /* Otherwise, just years. Centuries is probably overkill. */ + snprintf(timebuf, sizeof(timebuf), "%lu years ago", (diff + 183) / 365); + return timebuf; } if (mode == DATE_LOCAL)