[MNG-5975] Use Java 7's SimpleDateFormat in CLIReportingUtils#formatTimestamp
Project: http://git-wip-us.apache.org/repos/asf/maven/repo Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/355f4dff Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/355f4dff Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/355f4dff Branch: refs/heads/MNG-5958-IT Commit: 355f4dff03cea8cab0d7bdcb00fffa4e43b2c10b Parents: a2358ba Author: Michael Osipov <micha...@apache.org> Authored: Fri Feb 12 23:30:47 2016 +0100 Committer: Michael Osipov <micha...@apache.org> Committed: Sun Jan 22 21:37:57 2017 +0100 ---------------------------------------------------------------------- .../org/apache/maven/cli/CLIReportingUtils.java | 32 ++++++-------------- 1 file changed, 10 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven/blob/355f4dff/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java ---------------------------------------------------------------------- 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 2397d5d..214704b 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 @@ package org.apache.maven.cli; * 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 final class CLIReportingUtils 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%<tT%s%02d:%02d", timestamp, offsetSign, h, m ); + SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssXXX" ); + return sdf.format( new Date( timestamp ) ); } public static String formatDuration( long duration ) @@ -185,18 +169,22 @@ public final class CLIReportingUtils String format; if ( d > 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"; }