public static final String getDurationUnits ( final String duration ) { if ( duration == null || duration . isEmpty ( ) ) { throw new IllegalArgumentException ( "Duration cannot be null or empty" ) ; } int unit = 0 ; while ( unit < duration . length ( ) && Character . isDigit ( duration . charAt ( unit ) ) ) { unit ++ ; } final String units = duration . substring ( unit ) . toLowerCase ( ) ; if ( units . equals ( "ms" ) || units . equals ( "s" ) || units . equals ( "m" ) || units . equals ( "h" ) || units . equals ( "d" ) || units . equals ( "w" ) || units . equals ( "n" ) || units . equals ( "y" ) ) { return units ; } throw new IllegalArgumentException ( "Invalid units in the duration: " + units ) ; }
Returns the suffix or units of the duration as a string . The result will be ms s m h d w n or y .