summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2009-03-05 15:41:43 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2009-03-05 15:41:43 -0800
commit3535dbb3d10cb2782dfbb77c07f2f7d9c44bd41f (patch)
tree47f4d03f1ede4de1bd4db65b6e6d031e6f329ae0
parentMerge branch 'fc/config-editor' (diff)
parentnever fallback relative times to absolute (diff)
downloadtgif-3535dbb3d10cb2782dfbb77c07f2f7d9c44bd41f.tar.xz
Merge branch 'jk/sane-relative-time'
* jk/sane-relative-time: never fallback relative times to absolute
-rw-r--r--date.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/date.c b/date.c
index d75dff4240..1165d30adf 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)