public static long parseTimePeriod ( String period ) { try { String s = period . toLowerCase ( ) ; long factor ; // look for suffix if ( s . endsWith ( "msec" ) ) { s = s . substring ( 0 , s . lastIndexOf ( "msec" ) ) ; factor = MSEC ; } else if ( s . endsWith ( "sec" ) ) { s = s . substring ( 0 , s . lastIndexOf ( "sec" ) ) ; factor = SECS ; } else if ( s . endsWith ( "min" ) ) { s = s . substring ( 0 , s . lastIndexOf ( "min" ) ) ; factor = MINS ; } else if ( s . endsWith ( "h" ) ) { s = s . substring ( 0 , s . lastIndexOf ( "h" ) ) ; factor = HOUR ; } else { factor = 1 ; } return Long . parseLong ( s ) * factor ; } catch ( RuntimeException e ) { // thrown in addition when period is 'null' throw new NumberFormatException ( "For input time period: '" + period + "'" ) ; } }
Parses a time period into a long .