aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.junit
diff options
context:
space:
mode:
authorIvan Frade <ifrade@google.com>2024-11-04 14:21:24 -0800
committerMatthias Sohn <matthias.sohn@sap.com>2024-11-08 01:06:58 +0100
commit88f8321bafeb9476bbb9b42b349521c68e375e4f (patch)
treea1266108e4557ec28bc4b75bb4ff044391bda40b /org.eclipse.jgit.junit
parentb2accb0e9c07fa40fa9d7bf266a5763a1f63cc90 (diff)
downloadjgit-88f8321bafeb9476bbb9b42b349521c68e375e4f.tar.gz
jgit-88f8321bafeb9476bbb9b42b349521c68e375e4f.zip
SystemReader: Offer methods with java.time API
Error prone explains: The Date API is full of major design flaws and pitfalls and should be avoided at all costs. Prefer the java.time APIs, specifically, java.time.Instant (for physical time) and java.time.LocalDate[Time] (for civil time). Add to SystemReader methods to get the time and timezone in the new java.time classes (Instant/ZoneId) and mark as deprecated their old counterparts. The mapping of methods is: * #getCurrentTime -> #now (returns Instant instead of int) * #getTimezone -> #getTimeZoneAt (returns ZoneOffset intead of int) * #getTimeZone -> #getTimeZoneId (return ZoneId instead of TimeZone) Change-Id: Ic55b2f442a40046ff0ed24f61f566fc7416471be
Diffstat (limited to 'org.eclipse.jgit.junit')
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java
index 419fdb1966..b0365aa7e1 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java
@@ -18,6 +18,9 @@ import java.lang.reflect.Field;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.Duration;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.ZoneOffset;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
@@ -202,6 +205,11 @@ public class MockSystemReader extends SystemReader {
}
@Override
+ public Instant now() {
+ return Instant.ofEpochMilli(now);
+ }
+
+ @Override
public MonotonicClock getClock() {
return () -> {
long t = getCurrentTime();
@@ -237,11 +245,21 @@ public class MockSystemReader extends SystemReader {
}
@Override
+ public ZoneOffset getTimeZoneAt(Instant when) {
+ return getTimeZoneId().getRules().getOffset(when);
+ }
+
+ @Override
public TimeZone getTimeZone() {
return TimeZone.getTimeZone("GMT-03:30");
}
@Override
+ public ZoneId getTimeZoneId() {
+ return ZoneOffset.ofHoursMinutes(-3, 30);
+ }
+
+ @Override
public Locale getLocale() {
return Locale.US;
}