diff options
author | Michael Keppler <Michael.Keppler@gmx.de> | 2017-10-12 09:38:31 +0200 |
---|---|---|
committer | David Pursehouse <david.pursehouse@gmail.com> | 2017-10-23 11:33:55 +0900 |
commit | e1a39cbbe7c9f317b5f9ff6f4b7792eb2b837a09 (patch) | |
tree | 252f85dc7c13afc7cd1b1363889798faf929502c /org.eclipse.jgit/src | |
parent | adbf0935e105819f6b8f65325013b6def6205f18 (diff) | |
download | jgit-e1a39cbbe7c9f317b5f9ff6f4b7792eb2b837a09.tar.gz jgit-e1a39cbbe7c9f317b5f9ff6f4b7792eb2b837a09.zip |
Avoid bad rounding "1 year, 12 months" in date formatter
Round first, then calculate the labels. This avoids "x years, 12 months"
and instead produces "x+1 years".
One test case has been added for the original example the bug was found
with, and one assertion has been moved from an existing test case to the
new test case, since it also triggered the bug.
Bug: 525907
Change-Id: I3270af3850c4fb7bae9123a0a6582f93055c9780
Signed-off-by: Michael Keppler <Michael.Keppler@gmx.de>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit/src')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/util/RelativeDateFormatter.java | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/RelativeDateFormatter.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/RelativeDateFormatter.java index 21a55a602b..a5df66e99c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/RelativeDateFormatter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/RelativeDateFormatter.java @@ -114,10 +114,11 @@ 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) ? 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( |