From fb68c7a4cddc9e207f3f191d4bb73e809790cffd Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Sun, 9 Oct 2011 14:47:49 +0200 Subject: [PATCH] Use the SystemReader to get system time Change-Id: Ib79c0cc964bfe799b204419e552b9aa6243966ce --- .../eclipse/jgit/util/RelativeDateFormatterTest.java | 10 +++++++++- .../org/eclipse/jgit/util/RelativeDateFormatter.java | 3 ++- 2 files changed, 11 insertions(+), 2 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 4b45209ea..18d4e1060 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 @@ -51,14 +51,22 @@ import static org.eclipse.jgit.util.RelativeDateFormatter.DAY_IN_MILLIS; import java.util.Date; +import org.eclipse.jgit.junit.MockSystemReader; import org.eclipse.jgit.util.RelativeDateFormatter; +import org.junit.Before; import org.junit.Test; public class RelativeDateFormatterTest { + @Before + public void setUp() { + SystemReader.setInstance(new MockSystemReader()); + } + private void assertFormat(long ageFromNow, long timeUnit, String expectedFormat) { - Date d = new Date(System.currentTimeMillis() - ageFromNow * timeUnit); + Date d = new Date(SystemReader.getInstance().getCurrentTime() + - ageFromNow * timeUnit); String s = RelativeDateFormatter.format(d); assertEquals(expectedFormat, s); } 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 bcbcd808d..203e24799 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/RelativeDateFormatter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/RelativeDateFormatter.java @@ -75,7 +75,8 @@ public class RelativeDateFormatter { @SuppressWarnings("boxing") public static String format(Date when) { - long ageMillis = (System.currentTimeMillis() - when.getTime()); + long ageMillis = SystemReader.getInstance().getCurrentTime() + - when.getTime(); // shouldn't happen in a perfect world if (ageMillis < 0)