summaryrefslogtreecommitdiffstats
path: root/gerrit-gwtui-common
diff options
context:
space:
mode:
authorEdwin Kempin <ekempin@google.com>2017-10-05 13:39:07 +0200
committerEdwin Kempin <ekempin@google.com>2017-10-05 13:39:07 +0200
commit289adc47e7414d99571a6a27e1b78d364e13f5e3 (patch)
treea6a1146715bf9205d10ded78f02ab432ac840be0 /gerrit-gwtui-common
parentdecff23529d75d8ee246ad986ce0a560e51300d5 (diff)
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>
Diffstat (limited to 'gerrit-gwtui-common')
-rw-r--r--gerrit-gwtui-common/src/main/java/com/google/gerrit/client/RelativeDateFormatter.java4
-rw-r--r--gerrit-gwtui-common/src/test/java/com/google/gerrit/client/RelativeDateFormatterTest.java2
2 files changed, 5 insertions, 1 deletions
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 2f0df8c348..a0c4aa68eb 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 @@ 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);
}
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 513d95ad5d..51804100af 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 @@ 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