From 355f4dff03cea8cab0d7bdcb00fffa4e43b2c10b Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Fri, 12 Feb 2016 23:30:47 +0100 Subject: [PATCH] [MNG-5975] Use Java 7's SimpleDateFormat in CLIReportingUtils#formatTimestamp --- .../apache/maven/cli/CLIReportingUtils.java | 32 ++++++------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java index 2397d5d033..214704b9ea 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java @@ -19,15 +19,15 @@ * under the License. */ -import org.codehaus.plexus.util.Os; -import org.slf4j.Logger; - import java.io.IOException; import java.io.InputStream; +import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.Properties; -import java.util.TimeZone; + +import org.codehaus.plexus.util.Os; +import org.slf4j.Logger; /** * Utility class used to report errors, statistics, application version info, etc. @@ -152,24 +152,8 @@ public static void showError( Logger logger, String message, Throwable e, boolea public static String formatTimestamp( long timestamp ) { - // Manual construction of the tz offset because only Java 7 is aware of ISO 8601 time zones - TimeZone tz = TimeZone.getDefault(); - int offset = tz.getRawOffset(); - - // Raw offset ignores DST, so check if we are in DST now and add the offset - if ( tz.inDaylightTime( new Date( timestamp ) ) ) - { - offset += tz.getDSTSavings(); - } - - // CHECKSTYLE_OFF: MagicNumber - long m = Math.abs( ( offset / ONE_MINUTE ) % 60 ); - long h = Math.abs( ( offset / ONE_HOUR ) % 24 ); - // CHECKSTYLE_ON: MagicNumber - - int offsetDir = (int) Math.signum( (float) offset ); - char offsetSign = offsetDir >= 0 ? '+' : '-'; - return String.format( "%tFT% 0 ) { + // Length 11+ chars format = "%d d %02d:%02d h"; } else if ( h > 0 ) { + // Length 7 chars format = "%2$02d:%3$02d h"; } else if ( m > 0 ) { + // Length 9 chars format = "%3$02d:%4$02d min"; } else { + // Length 7-8 chars format = "%4$d.%5$03d s"; }