public static String getDurationFormattedString ( final long startMillis , final long endMillis , final VaadinMessageSource i18N ) { final String formatDuration = DurationFormatUtils . formatPeriod ( startMillis , endMillis , DURATION_FORMAT , false , getBrowserTimeZone ( ) ) ; final StringBuilder formattedDuration = new StringBuilder ( ) ; final String [ ] split = formatDuration . split ( "," ) ; for ( int index = 0 ; index < split . length ; index ++ ) { if ( index != 0 && formattedDuration . length ( ) > 0 ) { formattedDuration . append ( ' ' ) ; } final int value = Integer . parseInt ( split [ index ] ) ; if ( value != 0 ) { final String suffix = ( value == 1 ) ? i18N . getMessage ( DURATION_I18N . get ( index ) . getSingle ( ) ) : i18N . getMessage ( DURATION_I18N . get ( index ) . getPlural ( ) ) ; formattedDuration . append ( value ) . append ( ' ' ) . append ( suffix ) ; } } return formattedDuration . toString ( ) ; }
Creates a formatted string of a duration in format 1 year 2 months 3 days 4 hours 5 minutes 6 seconds zero values will be ignored in the formatted string .