summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-04-27 11:36:43 -0700
committerJunio C Hamano <gitster@pobox.com>2011-04-27 11:36:43 -0700
commit9f5df6fa670938a505a64edf1b779b1326311481 (patch)
tree2c0081a3816b1ba8e580d3120ed2e00e2f9173b5
parent5033de916a1863d640d57dad238521411c1ed5ff (diff)
parentf1e9c548ce45005521892af0299696204ece286b (diff)
downloadgit-9f5df6fa670938a505a64edf1b779b1326311481.tar.gz
Merge branch 'mg/x-years-12-months'
* mg/x-years-12-months: date: avoid "X years, 12 months" in relative dates
-rw-r--r--date.c5
-rwxr-xr-xt/t0006-date.sh1
2 files changed, 4 insertions, 2 deletions
diff --git a/date.c b/date.c
index 00f9eb5d0b..896fbb4806 100644
--- a/date.c
+++ b/date.c
@@ -129,8 +129,9 @@ const char *show_date_relative(unsigned long time, int tz,
}
/* Give years and months for 5 years or so */
if (diff < 1825) {
- unsigned long years = diff / 365;
- unsigned long months = (diff % 365 + 15) / 30;
+ unsigned long totalmonths = (diff * 12 * 2 + 365) / (365 * 2);
+ unsigned long years = totalmonths / 12;
+ unsigned long months = totalmonths % 12;
int n;
n = snprintf(timebuf, timebuf_size, "%lu year%s",
years, (years > 1 ? "s" : ""));
diff --git a/t/t0006-date.sh b/t/t0006-date.sh
index 1d4d0a5c7d..f87abb5a06 100755
--- a/t/t0006-date.sh
+++ b/t/t0006-date.sh
@@ -25,6 +25,7 @@ check_show 37500000 '1 year, 2 months ago'
check_show 55188000 '1 year, 9 months ago'
check_show 630000000 '20 years ago'
check_show 31449600 '12 months ago'
+check_show 62985600 '2 years ago'
check_parse() {
echo "$1 -> $2" >expect