Fix bad rounding of relative dates like '1 year, 12 months ago'

Instead of '1 year, 12 months ago' it should say '2 years ago'.

Bug: Issue 7357
Change-Id: I8b1af0e72e295b667ade7f6405378222f127644b
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2017-10-05 13:39:07 +02:00
parent decff23529
commit 289adc47e7
2 changed files with 5 additions and 1 deletions

View File

@@ -121,6 +121,10 @@ public class RelativeDateFormatter {
if (months == 0) {
return m().years0MonthsAgo(years, yearLabel);
}
if (months == 12) {
years++;
return m().years0MonthsAgo(years, yearLabel);
}
return m().yearsMonthsAgo(years, yearLabel, months, monthLabel);
}

View File

@@ -97,7 +97,7 @@ public class RelativeDateFormatterTest {
assertFormat(380, DAY_IN_MILLIS, "1 year, 1 month ago");
assertFormat(410, DAY_IN_MILLIS, "1 year, 2 months ago");
assertFormat(2, YEAR_IN_MILLIS, "2 years ago");
assertFormat(1824, DAY_IN_MILLIS, "4 years, 12 months ago");
assertFormat(1824, DAY_IN_MILLIS, "5 years ago");
}
@Test