[MNG-5906] Use canonical name for UTC timezone

This commit is contained in:
Michael Osipov 2015-10-10 14:39:31 +02:00
parent bcacea2cfb
commit b711de57dc
4 changed files with 18 additions and 13 deletions

View File

@ -41,6 +41,9 @@ import org.eclipse.aether.artifact.Artifact;
final class RemoteSnapshotMetadata
extends MavenSnapshotMetadata
{
private static final String DEFAULT_SNAPSHOT_TIMESTAMP_FORMAT = "yyyyMMdd.HHmmss";
private static final TimeZone DEFAULT_SNAPSHOT_TIME_ZONE = TimeZone.getTimeZone( "Etc/UTC" );
private final Map<String, SnapshotVersion> versions = new LinkedHashMap<>();
@ -73,9 +76,9 @@ final class RemoteSnapshotMetadata
if ( metadata.getVersioning() == null )
{
DateFormat utcDateFormatter = new SimpleDateFormat( "yyyyMMdd.HHmmss" );
DateFormat utcDateFormatter = new SimpleDateFormat( DEFAULT_SNAPSHOT_TIMESTAMP_FORMAT );
utcDateFormatter.setCalendar( new GregorianCalendar() );
utcDateFormatter.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
utcDateFormatter.setTimeZone( DEFAULT_SNAPSHOT_TIME_ZONE );
snapshot = new Snapshot();
snapshot.setBuildNumber( getBuildNumber( recessive ) + 1 );

View File

@ -46,12 +46,12 @@ import org.codehaus.plexus.util.StringUtils;
public class SnapshotTransformation
extends AbstractVersionTransformation
{
private static final String DEFAULT_SNAPSHOT_TIMESTAMP_FORMAT = "yyyyMMdd.HHmmss";
private static final TimeZone DEFAULT_SNAPSHOT_TIME_ZONE = TimeZone.getTimeZone( "Etc/UTC" );
private String deploymentTimestamp;
private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" );
private static final String UTC_TIMESTAMP_PATTERN = "yyyyMMdd.HHmmss";
public void transformForResolve( Artifact artifact, RepositoryRequest request )
throws ArtifactResolutionException
{
@ -163,8 +163,8 @@ public class SnapshotTransformation
public static DateFormat getUtcDateFormatter()
{
DateFormat utcDateFormatter = new SimpleDateFormat( UTC_TIMESTAMP_PATTERN );
utcDateFormatter.setTimeZone( UTC_TIME_ZONE );
DateFormat utcDateFormatter = new SimpleDateFormat( DEFAULT_SNAPSHOT_TIMESTAMP_FORMAT );
utcDateFormatter.setTimeZone( DEFAULT_SNAPSHOT_TIME_ZONE );
return utcDateFormatter;
}

View File

@ -31,6 +31,8 @@ public class MavenBuildTimestamp
public static final String BUILD_TIMESTAMP_FORMAT_PROPERTY = "maven.build.timestamp.format";
public static final TimeZone DEFAULT_BUILD_TIME_ZONE = TimeZone.getTimeZone( "Etc/UTC" );
private String formattedTimestamp;
public MavenBuildTimestamp()
@ -59,7 +61,7 @@ public class MavenBuildTimestamp
time = new Date();
}
SimpleDateFormat dateFormat = new SimpleDateFormat( timestampFormat );
dateFormat.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
dateFormat.setTimeZone( DEFAULT_BUILD_TIME_ZONE );
formattedTimestamp = dateFormat.format( time );
}

View File

@ -88,7 +88,7 @@ public abstract class AbstractModelInterpolatorTest
public void testDefaultBuildTimestampFormatShouldFormatTimeIn24HourFormat()
{
Calendar cal = Calendar.getInstance();
cal.setTimeZone(TimeZone.getTimeZone("UTC"));
cal.setTimeZone( MavenBuildTimestamp.DEFAULT_BUILD_TIME_ZONE );
cal.set( Calendar.HOUR, 12 );
cal.set( Calendar.AM_PM, Calendar.AM );
@ -112,7 +112,7 @@ public abstract class AbstractModelInterpolatorTest
SimpleDateFormat format =
new SimpleDateFormat( MavenBuildTimestamp.DEFAULT_BUILD_TIMESTAMP_FORMAT );
format.setTimeZone(TimeZone.getTimeZone("UTC"));
format.setTimeZone( MavenBuildTimestamp.DEFAULT_BUILD_TIME_ZONE );
assertEquals( "1976-11-11T00:16:00Z", format.format( firstTestDate ) );
assertEquals( "1976-11-11T23:16:00Z", format.format( secondTestDate ) );
}
@ -120,7 +120,7 @@ public abstract class AbstractModelInterpolatorTest
public void testDefaultBuildTimestampFormatWithLocalTimeZoneMidnightRollover()
{
Calendar cal = Calendar.getInstance();
cal.setTimeZone(TimeZone.getTimeZone("Europe/Berlin"));
cal.setTimeZone( TimeZone.getTimeZone( "Europe/Berlin" ) );
cal.set( Calendar.HOUR_OF_DAY, 1 );
cal.set( Calendar.MINUTE, 16 );
@ -137,7 +137,7 @@ public abstract class AbstractModelInterpolatorTest
SimpleDateFormat format =
new SimpleDateFormat( MavenBuildTimestamp.DEFAULT_BUILD_TIMESTAMP_FORMAT );
format.setTimeZone(TimeZone.getTimeZone("UTC"));
format.setTimeZone( MavenBuildTimestamp.DEFAULT_BUILD_TIME_ZONE );
assertEquals( "2014-06-15T23:16:00Z", format.format( firstTestDate ) );
assertEquals( "2014-11-16T00:16:00Z", format.format( secondTestDate ) );
}