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:
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user