Merge branch 'stable-2.14' into stable-2.15
* stable-2.14: RelativeDateFormatter: Simplify rounding of years and months Change-Id: I892c18b9d1c75678586ecf757187eae64ce01cd2
This commit is contained in:
commit
45cbf3e713
@ -114,20 +114,13 @@ public class RelativeDateFormatter {
|
|||||||
|
|
||||||
// up to 5 years use "year, months" rounded to months
|
// up to 5 years use "year, months" rounded to months
|
||||||
if (ageMillis < 5 * YEAR_IN_MILLIS) {
|
if (ageMillis < 5 * YEAR_IN_MILLIS) {
|
||||||
long years = ageMillis / YEAR_IN_MILLIS;
|
long years = round(ageMillis, MONTH_IN_MILLIS) / 12;
|
||||||
String yearLabel = (years > 1) ? c().years() : c().year();
|
String yearLabel = (years > 1) ? c().years() : c().year();
|
||||||
long months = round(ageMillis % YEAR_IN_MILLIS, MONTH_IN_MILLIS);
|
long months = round(ageMillis - years * YEAR_IN_MILLIS, MONTH_IN_MILLIS);
|
||||||
String monthLabel = (months > 1) ? c().months() : (months == 1 ? c().month() : "");
|
String monthLabel = (months > 1) ? c().months() : (months == 1 ? c().month() : "");
|
||||||
if (months == 0) {
|
if (months == 0) {
|
||||||
return m().years0MonthsAgo(years, yearLabel);
|
return m().years0MonthsAgo(years, yearLabel);
|
||||||
}
|
}
|
||||||
if (months == 12) {
|
|
||||||
years++;
|
|
||||||
if (years > 1) {
|
|
||||||
yearLabel = c().years();
|
|
||||||
}
|
|
||||||
return m().years0MonthsAgo(years, yearLabel);
|
|
||||||
}
|
|
||||||
return m().yearsMonthsAgo(years, yearLabel, months, monthLabel);
|
return m().yearsMonthsAgo(years, yearLabel, months, monthLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user