diff options
author | Junio C Hamano <gitster@pobox.com> | 2009-03-11 13:59:38 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-03-11 13:59:38 -0700 |
commit | ecab04d49a53669d0f0d7afa677717570790b43a (patch) | |
tree | a1841056c292e733b55d70568dbab7d270fabc09 | |
parent | 6c3b3e141f289ffc5916f65f2fe307bc0bcd5dd8 (diff) | |
parent | 10edf37796badc58239eb3e5d1e8e608f6e1473c (diff) | |
download | git-ecab04d49a53669d0f0d7afa677717570790b43a.tar.gz git-ecab04d49a53669d0f0d7afa677717570790b43a.tar.xz |
Merge branch 'jk/sane-relative-time' into maint
* jk/sane-relative-time:
never fallback relative times to absolute
-rw-r--r-- | date.c | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -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) |