diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2024-12-25 01:05:32 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2024-12-25 13:48:43 +0100 |
commit | a2c281f39f9a455bce18efc166d81887245c880a (patch) | |
tree | f710dddad7d82dcc4f972126d9e492268a12e7df | |
parent | fc5cbf1d778f705acd1c388208846040cb7fa70a (diff) | |
download | jgit-a2c281f39f9a455bce18efc166d81887245c880a.tar.gz jgit-a2c281f39f9a455bce18efc166d81887245c880a.zip |
Show: use java.time API
We are moving away from the old java.util.Date API to the
java.time API.
Change-Id: I19a705329e5bae66df6532b956d74c981dde6f57
-rw-r--r-- | org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Show.java | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Show.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Show.java index 1576792234..a3a6782a71 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Show.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Show.java @@ -14,11 +14,10 @@ package org.eclipse.jgit.pgm; import java.io.BufferedOutputStream; import java.io.IOException; -import java.text.DateFormat; import java.text.MessageFormat; -import java.text.SimpleDateFormat; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.util.Locale; -import java.util.TimeZone; import org.eclipse.jgit.diff.DiffFormatter; import org.eclipse.jgit.diff.RawTextComparator; @@ -51,9 +50,9 @@ import org.kohsuke.args4j.Option; @Command(common = true, usage = "usage_show") class Show extends TextBuiltin { - private final TimeZone myTZ = TimeZone.getDefault(); + private final ZoneId myTZ = ZoneId.systemDefault(); - private final DateFormat fmt; + private final DateTimeFormatter fmt; private DiffFormatter diffFmt; @@ -157,7 +156,8 @@ class Show extends TextBuiltin { // END -- Options shared with Diff Show() { - fmt = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy ZZZZZ", Locale.US); //$NON-NLS-1$ + fmt = DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss yyyy ZZ", //$NON-NLS-1$ + Locale.US); } @Override @@ -232,15 +232,17 @@ class Show extends TextBuiltin { outw.print(tag.getTagName()); outw.println(); - final PersonIdent tagger = tag.getTaggerIdent(); + PersonIdent tagger = tag.getTaggerIdent(); if (tagger != null) { outw.println(MessageFormat.format(CLIText.get().taggerInfo, tagger.getName(), tagger.getEmailAddress())); - final TimeZone taggerTZ = tagger.getTimeZone(); - fmt.setTimeZone(taggerTZ != null ? taggerTZ : myTZ); + ZoneId taggerTZ = tagger.getZoneId(); + String formattedTaggerTime = fmt + .withZone(taggerTZ != null ? taggerTZ : myTZ) + .format(tagger.getWhenAsInstant()); outw.println(MessageFormat.format(CLIText.get().dateInfo, - fmt.format(tagger.getWhen()))); + formattedTaggerTime)); } outw.println(); @@ -293,10 +295,12 @@ class Show extends TextBuiltin { outw.println(MessageFormat.format(CLIText.get().authorInfo, author.getName(), author.getEmailAddress())); - final TimeZone authorTZ = author.getTimeZone(); - fmt.setTimeZone(authorTZ != null ? authorTZ : myTZ); + final ZoneId authorTZ = author.getZoneId(); + String formattedAuthorTime = fmt + .withZone(authorTZ != null ? authorTZ : myTZ) + .format(author.getWhenAsInstant()); outw.println(MessageFormat.format(CLIText.get().dateInfo, - fmt.format(author.getWhen()))); + formattedAuthorTime)); outw.println(); final String[] lines = c.getFullMessage().split("\n"); //$NON-NLS-1$ |