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");
+ }
+
+ @Test
+ public void testFullYearMissingSomeDays() {
+ // avoid "x year(s), 12 months", as humans would always round this up to
+ // "x+1 years"
+ assertFormat(5 * 365 + 1, DAY_IN_MILLIS, "5 years ago");
+ assertFormat(2 * 365 - 10, DAY_IN_MILLIS, "2 years ago");
}
@Test
// up to 5 years use "year, months" rounded to months
if (ageMillis < 5 * YEAR_IN_MILLIS) {
- long years = ageMillis / YEAR_IN_MILLIS;
+ long years = round(ageMillis, MONTH_IN_MILLIS) / 12;
String yearLabel = (years > 1) ? JGitText.get().years : //
JGitText.get().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) ? JGitText.get().months : //
(months == 1 ? JGitText.get().month : ""); //$NON-NLS-1$
return MessageFormat.format(