diff options
author | Paul Pazderski | 2020-02-17 08:57:01 +0000 |
---|---|---|
committer | Paul Pazderski | 2020-02-17 08:59:17 +0000 |
commit | 6e2746047336862f17bf2e0a73cb95e43565a658 (patch) | |
tree | 9bb1f5a6d05d52d11097d667a91d16c5bbdef7d3 | |
parent | 296b2b78ef97e1aecb6e46e0eb45e4aed37c0ffb (diff) | |
download | eclipse.platform.debug-6e2746047336862f17bf2e0a73cb95e43565a658.tar.gz eclipse.platform.debug-6e2746047336862f17bf2e0a73cb95e43565a658.tar.xz eclipse.platform.debug-6e2746047336862f17bf2e0a73cb95e43565a658.zip |
Bug 251642 - [console] Shorten terminate timestamp for same day
If process started and terminated at same day (the most common case for
process run in IDE) do not show the day part twice.
Change-Id: I6b080af23b44b3bd6db5d6301794705fb5359c56
Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
-rw-r--r-- | org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java index de6f63c70..21247a6ad 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java @@ -26,6 +26,9 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.Charset; import java.text.ParseException; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -306,8 +309,8 @@ public class ProcessConsole extends IOConsole implements IConsole, IDebugEventSe buffer.append("] "); //$NON-NLS-1$ } - String launchTime = formatTimestamp(process.getAttribute(DebugPlugin.ATTR_LAUNCH_TIMESTAMP)); - String terminateTime = formatTimestamp(process.getAttribute(DebugPlugin.ATTR_TERMINATE_TIMESTAMP)); + Date launchTime = parseTimestamp(process.getAttribute(DebugPlugin.ATTR_LAUNCH_TIMESTAMP)); + Date terminateTime = parseTimestamp(process.getAttribute(DebugPlugin.ATTR_TERMINATE_TIMESTAMP)); String procLabel = process.getLabel(); if (launchTime != null) { @@ -328,15 +331,32 @@ public class ProcessConsole extends IOConsole implements IConsole, IDebugEventSe } } + DateFormat dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); if (launchTime != null && terminateTime != null) { + String launchTimeStr = dateTimeFormat.format(launchTime); + // Check if process started and terminated at same day. If so only print the + // time part of termination time and omit the date part. + LocalDateTime launchDate = LocalDateTime.ofInstant(launchTime.toInstant(), + ZoneId.systemDefault()); + LocalDateTime terminateDate = LocalDateTime.ofInstant(terminateTime.toInstant(), + ZoneId.systemDefault()); + LocalDateTime launchDay = launchDate.truncatedTo(ChronoUnit.DAYS); + LocalDateTime terminateDay = terminateDate.truncatedTo(ChronoUnit.DAYS); + String terminateTimeStr; + if (launchDay.equals(terminateDay)) { + terminateTimeStr = DateFormat.getTimeInstance(DateFormat.MEDIUM).format(terminateTime); + } else { + terminateTimeStr = dateTimeFormat.format(terminateTime); + } + buffer.append(MessageFormat.format(ConsoleMessages.ProcessConsole_commandLabel_withStartEnd, - procLabel, launchTime, terminateTime)); + procLabel, launchTimeStr, terminateTimeStr)); } else if (launchTime != null) { buffer.append(MessageFormat.format(ConsoleMessages.ProcessConsole_commandLabel_withStart, - procLabel, launchTime)); + procLabel, dateTimeFormat.format(launchTime))); } else if (terminateTime != null) { buffer.append(MessageFormat.format(ConsoleMessages.ProcessConsole_commandLabel_withEnd, - procLabel, terminateTime)); + procLabel, dateTimeFormat.format(terminateTime))); } label = buffer.toString(); } @@ -350,20 +370,20 @@ public class ProcessConsole extends IOConsole implements IConsole, IDebugEventSe } /** - * Format timestamp as datetime. + * Get Date from (possibly invalid) timestamp. * * @param timestamp a timestamp as returned from * {@link System#currentTimeMillis()} or <code>null</code> - * @return timestamp formatted as datetime or <code>null</code> if timestamp is + * @return Date object for this timestamp or <code>null</code> if timestamp is * invalid */ - private static String formatTimestamp(String timestamp) { + private static Date parseTimestamp(String timestamp) { if (timestamp == null) { return null; } try { long lTimestamp = Long.parseLong(timestamp); - return DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(new Date(lTimestamp)); + return new Date(lTimestamp); } catch (NumberFormatException ex) { return null; } |