diff options
author | David Pursehouse <dpursehouse@collab.net> | 2017-10-13 21:31:28 +0900 |
---|---|---|
committer | David Pursehouse <dpursehouse@collab.net> | 2017-10-13 21:33:33 +0900 |
commit | 24796d957abb610339c9078b0c13b2782e587c5d (patch) | |
tree | e0669ffd1a0b6ecb0926e596f64092216eaec2c8 /gerrit-gwtui-common | |
parent | 1b596afc4d9c6263125c42b3709d0a53c94b021c (diff) |
RelativeDateFormatter: Simplify rounding of years and months
Instead of adjusting the years and months values after first
incorrectly calculating them, fix the calculation.
Based on the implementation proposed in [1]
[1] https://git.eclipse.org/r/#/c/109895/
Also-by: Michael Keppler <Michael.Keppler@gmx.de>
Change-Id: I9a48183c9a16fda2ea0d2521a7cd0b1a5e5f2f45
Diffstat (limited to 'gerrit-gwtui-common')
-rw-r--r-- | gerrit-gwtui-common/src/main/java/com/google/gerrit/client/RelativeDateFormatter.java | 11 |
1 files changed, 2 insertions, 9 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 fdd6454095..e0cc9ca65e 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 @@ -114,20 +114,13 @@ public class RelativeDateFormatter { // 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) ? 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() : ""); if (months == 0) { 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); } |