aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org
diff options
context:
space:
mode:
authorMichael Keppler <Michael.Keppler@gmx.de>2017-10-12 09:38:31 +0200
committerDavid Pursehouse <david.pursehouse@gmail.com>2017-10-23 11:33:55 +0900
commite1a39cbbe7c9f317b5f9ff6f4b7792eb2b837a09 (patch)
tree252f85dc7c13afc7cd1b1363889798faf929502c /org.eclipse.jgit.test/tst/org
parentadbf0935e105819f6b8f65325013b6def6205f18 (diff)
downloadjgit-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.test/tst/org')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RelativeDateFormatterTest.java9
1 files changed, 8 insertions, 1 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RelativeDateFormatterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RelativeDateFormatterTest.java
index 76687d15a5..fb76ec4e59 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RelativeDateFormatterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RelativeDateFormatterTest.java
@@ -128,7 +128,14 @@ 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");
+ }
+
+ @Test
+ public void testFullYearMissingSomeDays() {
+ // avoid "x year(s), 12 months", as humans would always round this up to
+ // "x+1 years"
+ assertFormat(5 * 365 + 1, DAY_IN_MILLIS, "5 years ago");
+ assertFormat(2 * 365 - 10, DAY_IN_MILLIS, "2 years ago");
}
@Test