From 289adc47e7414d99571a6a27e1b78d364e13f5e3 Mon Sep 17 00:00:00 2001 From: Edwin Kempin Date: Thu, 5 Oct 2017 13:39:07 +0200 Subject: [PATCH] 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 --- .../java/com/google/gerrit/client/RelativeDateFormatter.java | 4 ++++ .../com/google/gerrit/client/RelativeDateFormatterTest.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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