mirror of https://github.com/apache/maven.git
[MNG-5975] Use Java 7's SimpleDateFormat in CLIReportingUtils#formatTimestamp
This commit is contained in:
parent
a2358ba7bb
commit
355f4dff03
|
@ -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%<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 static String formatDuration( long duration )
|
|||
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";
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue