Skip to content

Commit 9f5df6f

Browse files
committed
Merge branch 'mg/x-years-12-months'
* mg/x-years-12-months: date: avoid "X years, 12 months" in relative dates
2 parents 5033de9 + f1e9c54 commit 9f5df6f

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

date.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ const char *show_date_relative(unsigned long time, int tz,
129129
}
130130
/* Give years and months for 5 years or so */
131131
if (diff < 1825) {
132-
unsigned long years = diff / 365;
133-
unsigned long months = (diff % 365 + 15) / 30;
132+
unsigned long totalmonths = (diff * 12 * 2 + 365) / (365 * 2);
133+
unsigned long years = totalmonths / 12;
134+
unsigned long months = totalmonths % 12;
134135
int n;
135136
n = snprintf(timebuf, timebuf_size, "%lu year%s",
136137
years, (years > 1 ? "s" : ""));

t/t0006-date.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ check_show 37500000 '1 year, 2 months ago'
2525
check_show 55188000 '1 year, 9 months ago'
2626
check_show 630000000 '20 years ago'
2727
check_show 31449600 '12 months ago'
28+
check_show 62985600 '2 years ago'
2829

2930
check_parse() {
3031
echo "$1 -> $2" >expect

0 commit comments

Comments
 (0)