in redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/util/DateUtils.java [54:114]
public static String formatWithAge( Date date, String dateFormat, String suffix )
{
if ( date == null )
{
return null;
}
SimpleDateFormat format = new SimpleDateFormat( dateFormat );
StringBuilder out = new StringBuilder();
out.append( format.format( date ) );
out.append( " - " );
Calendar now = Calendar.getInstance();
Calendar then = Calendar.getInstance();
then.setTime( date );
long diffMillis = now.getTimeInMillis() - then.getTimeInMillis();
long days = diffMillis / ( 24 * 60 * 60 * 1000 );
long hours = diffMillis / ( 60 * 60 * 1000 );
long minutes = diffMillis / ( 60 * 1000 );
long seconds = diffMillis / ( 1000 );
if ( days > 0 )
{
out.append( String.valueOf( days ) ).append( " day" );
if ( days > 1 )
{
out.append( 's' );
}
}
else if ( hours > 0 )
{
out.append( String.valueOf( hours ) ).append( " hour" );
if ( hours > 1 )
{
out.append( 's' );
}
}
else if ( minutes > 0 )
{
out.append( String.valueOf( minutes ) ).append( " minute" );
if ( minutes > 1 )
{
out.append( 's' );
}
}
else if ( seconds > 0 )
{
out.append( String.valueOf( seconds ) ).append( " second" );
if ( seconds > 1 )
{
out.append( 's' );
}
}
out.append( ' ' ).append( suffix );
return out.toString();
}