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>
diff --git a/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/RelativeDateFormatter.java b/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/RelativeDateFormatter.java
index 2f0df8c..a0c4aa6 100644
--- a/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/RelativeDateFormatter.java
+++ b/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/RelativeDateFormatter.java
@@ -121,6 +121,10 @@
if (months == 0) {
return m().years0MonthsAgo(years, yearLabel);
}
+ if (months == 12) {
+ years++;
+ return m().years0MonthsAgo(years, yearLabel);
+ }
return m().yearsMonthsAgo(years, yearLabel, months, monthLabel);
}
diff --git a/gerrit-gwtui-common/src/test/java/com/google/gerrit/client/RelativeDateFormatterTest.java b/gerrit-gwtui-common/src/test/java/com/google/gerrit/client/RelativeDateFormatterTest.java
index 513d95a..5180410 100644
--- a/gerrit-gwtui-common/src/test/java/com/google/gerrit/client/RelativeDateFormatterTest.java
+++ b/gerrit-gwtui-common/src/test/java/com/google/gerrit/client/RelativeDateFormatterTest.java
@@ -97,7 +97,7 @@
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