summaryrefslogtreecommitdiff
path: root/date.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2009-02-24 00:42:16 -0500
committerJunio C Hamano <gitster@pobox.com>2009-02-25 00:44:43 -0800
commit10edf37796badc58239eb3e5d1e8e608f6e1473c (patch)
tree7b1a5931d50bb76dff0901cb08c8e4c6d589d8b3 /date.c
parentd43c07b8ee6684a0df8636a0c849605f0ffc066f (diff)
downloadgit-10edf37796badc58239eb3e5d1e8e608f6e1473c.tar.gz
never fallback relative times to absolute
Previously, for dates older than 12 months we fell back to just giving the absolute time. This can be a bit jarring when reading a list of times. Instead, let's switch to "Y years, M months" for five years, and then just "Y years" after that. No particular reason on the 5 year cutoff except that it seemed reasonable to me. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'date.c')
-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)