aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm/src/org/eclipse
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2024-12-25 21:43:06 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2024-12-25 21:43:06 +0100
commitc17ebb09a43bdf9863bd9b2fdb28640cc559f420 (patch)
tree99ca4f540a926745aac93cc92e562aad410c26a5 /org.eclipse.jgit.pgm/src/org/eclipse
parentc2b2c3d1e2da84c932c4041da79bb556d101c102 (diff)
downloadjgit-c17ebb09a43bdf9863bd9b2fdb28640cc559f420.tar.gz
jgit-c17ebb09a43bdf9863bd9b2fdb28640cc559f420.zip
Blame: use java.time API
We are moving away from the old java.util.Date API to the java.time API. Change-Id: Ib54d66848b920436c40f7f754193a4dee9566feb
Diffstat (limited to 'org.eclipse.jgit.pgm/src/org/eclipse')
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java20
1 files changed, 11 insertions, 9 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java
index d2285ae64a..285fe2a96a 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java
@@ -18,7 +18,7 @@ import static org.eclipse.jgit.lib.Constants.OBJECT_ID_STRING_LENGTH;
import java.io.IOException;
import java.text.MessageFormat;
-import java.text.SimpleDateFormat;
+import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -91,7 +91,7 @@ class Blame extends TextBuiltin {
private final Map<RevCommit, String> abbreviatedCommits = new HashMap<>();
- private SimpleDateFormat dateFmt;
+ private DateTimeFormatter dateFmt;
private int begin;
@@ -125,9 +125,9 @@ class Blame extends TextBuiltin {
}
if (showRawTimestamp) {
- dateFmt = new SimpleDateFormat("ZZZZ"); //$NON-NLS-1$
+ dateFmt = DateTimeFormatter.ofPattern("ZZ"); //$NON-NLS-1$
} else {
- dateFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ZZZZ"); //$NON-NLS-1$
+ dateFmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss ZZ"); //$NON-NLS-1$
}
try (ObjectReader reader = db.newObjectReader();
@@ -335,12 +335,14 @@ class Blame extends TextBuiltin {
if (author == null)
return ""; //$NON-NLS-1$
- dateFmt.setTimeZone(author.getTimeZone());
- if (!showRawTimestamp)
- return dateFmt.format(author.getWhen());
+ if (!showRawTimestamp) {
+ return dateFmt.withZone(author.getZoneId())
+ .format(author.getWhenAsInstant());
+ }
return String.format("%d %s", //$NON-NLS-1$
- Long.valueOf(author.getWhen().getTime() / 1000L),
- dateFmt.format(author.getWhen()));
+ Long.valueOf(author.getWhenAsInstant().getEpochSecond()),
+ dateFmt.withZone(author.getZoneId())
+ .format(author.getWhenAsInstant()));
}
private String abbreviate(ObjectReader reader, RevCommit commit)