Browse Source

Use the SystemReader to get system time

Change-Id: Ib79c0cc964bfe799b204419e552b9aa6243966ce
stable-1.2
Robin Rosenberg 13 years ago
parent
commit
fb68c7a4cd
  1. 10
      org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RelativeDateFormatterTest.java
  2. 3
      org.eclipse.jgit/src/org/eclipse/jgit/util/RelativeDateFormatter.java

10
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 java.util.Date;
import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.util.RelativeDateFormatter; import org.eclipse.jgit.util.RelativeDateFormatter;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
public class RelativeDateFormatterTest { public class RelativeDateFormatterTest {
@Before
public void setUp() {
SystemReader.setInstance(new MockSystemReader());
}
private void assertFormat(long ageFromNow, long timeUnit, private void assertFormat(long ageFromNow, long timeUnit,
String expectedFormat) { String expectedFormat) {
Date d = new Date(System.currentTimeMillis() - ageFromNow * timeUnit); Date d = new Date(SystemReader.getInstance().getCurrentTime()
- ageFromNow * timeUnit);
String s = RelativeDateFormatter.format(d); String s = RelativeDateFormatter.format(d);
assertEquals(expectedFormat, s); assertEquals(expectedFormat, s);
} }

3
org.eclipse.jgit/src/org/eclipse/jgit/util/RelativeDateFormatter.java

@ -75,7 +75,8 @@ public class RelativeDateFormatter {
@SuppressWarnings("boxing") @SuppressWarnings("boxing")
public static String format(Date when) { 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 // shouldn't happen in a perfect world
if (ageMillis < 0) if (ageMillis < 0)

Loading…
Cancel
Save