mirror of
https://github.com/git/git.git
synced 2025-03-31 12:54:09 +00:00
Merge branch 'mg/x-years-12-months' into maint
* mg/x-years-12-months: date: avoid "X years, 12 months" in relative dates
This commit is contained in:
commit
04a67dc622
5
date.c
5
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 */
|
/* Give years and months for 5 years or so */
|
||||||
if (diff < 1825) {
|
if (diff < 1825) {
|
||||||
unsigned long years = diff / 365;
|
unsigned long totalmonths = (diff * 12 * 2 + 365) / (365 * 2);
|
||||||
unsigned long months = (diff % 365 + 15) / 30;
|
unsigned long years = totalmonths / 12;
|
||||||
|
unsigned long months = totalmonths % 12;
|
||||||
int n;
|
int n;
|
||||||
n = snprintf(timebuf, timebuf_size, "%lu year%s",
|
n = snprintf(timebuf, timebuf_size, "%lu year%s",
|
||||||
years, (years > 1 ? "s" : ""));
|
years, (years > 1 ? "s" : ""));
|
||||||
|
@ -25,6 +25,7 @@ check_show 37500000 '1 year, 2 months ago'
|
|||||||
check_show 55188000 '1 year, 9 months ago'
|
check_show 55188000 '1 year, 9 months ago'
|
||||||
check_show 630000000 '20 years ago'
|
check_show 630000000 '20 years ago'
|
||||||
check_show 31449600 '12 months ago'
|
check_show 31449600 '12 months ago'
|
||||||
|
check_show 62985600 '2 years ago'
|
||||||
|
|
||||||
check_parse() {
|
check_parse() {
|
||||||
echo "$1 -> $2" >expect
|
echo "$1 -> $2" >expect
|
||||||
|
Loading…
x
Reference in New Issue
Block a user