From 57bdb0487328b5ae46a255caa09360740ee28a17 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Fri, 21 Oct 2011 00:23:57 +0200 Subject: [PATCH] Cosmetic adjustment of relative date format, do not display "0 months" Though it may seem less precise, "0 months" looks bad and the reference Git implementation also does not display "0 months" Change-Id: I488e9c97656f9941788ae88d7c5c1562ab6c26f0 --- .../org/eclipse/jgit/util/RelativeDateFormatterTest.java | 4 ++-- .../resources/org/eclipse/jgit/JGitText.properties | 1 + org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java | 1 + .../src/org/eclipse/jgit/util/RelativeDateFormatter.java | 6 ++++-- 4 files changed, 8 insertions(+), 4 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 18d4e1060f..84b35b4dcd 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 @@ -119,10 +119,10 @@ public class RelativeDateFormatterTest { @Test public void testFormatYearsMonths() { - assertFormat(366, DAY_IN_MILLIS, "1 year, 0 month ago"); + assertFormat(366, DAY_IN_MILLIS, "1 year ago"); 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, 0 month ago"); + assertFormat(2, YEAR_IN_MILLIS, "2 years ago"); assertFormat(1824, DAY_IN_MILLIS, "4 years, 12 months ago"); } diff --git a/org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties b/org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties index de95b89698..d017bb7baf 100644 --- a/org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties +++ b/org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties @@ -493,5 +493,6 @@ year=year years=years yearsAgo={0} years ago yearsMonthsAgo={0} {1}, {2} {3} ago +years0MonthsAgo={0} {1} ago treeWalkMustHaveExactlyTwoTrees=TreeWalk should have exactly two trees. cannotBeRecursiveWhenTreesAreIncluded=TreeWalk shouldn't be recursive when tree objects are included. diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java index 7dbe158ce8..ceabe6d383 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java @@ -552,6 +552,7 @@ public class JGitText extends TranslationBundle { /***/ public String year; /***/ public String years; /***/ public String yearsAgo; + /***/ public String years0MonthsAgo; /***/ public String yearsMonthsAgo; /***/ public String treeWalkMustHaveExactlyTwoTrees; /***/ public String cannotBeRecursiveWhenTreesAreIncluded; 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 203e247996..02acb7ac1e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/RelativeDateFormatter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/RelativeDateFormatter.java @@ -119,8 +119,10 @@ public class RelativeDateFormatter { JGitText.get().year; long months = round(ageMillis % YEAR_IN_MILLIS, MONTH_IN_MILLIS); String monthLabel = (months > 1) ? JGitText.get().months : // - JGitText.get().month; - return MessageFormat.format(JGitText.get().yearsMonthsAgo, + (months == 1 ? JGitText.get().month : ""); + return MessageFormat.format( + months == 0 ? JGitText.get().years0MonthsAgo : JGitText + .get().yearsMonthsAgo, new Object[] { years, yearLabel, months, monthLabel }); } -- 2.39.5