Skip to content

Commit

Permalink
never fallback relative times to absolute
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
peff authored and gitster committed Feb 25, 2009
1 parent d43c07b commit 10edf37
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion date.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 10edf37

Please sign in to comment.