public static TimeUnit extractTimeUnitFromString ( String timeString ) { timeString = timeString . toLowerCase ( ) ; if ( timeString . contains ( "minute" ) ) { return TimeUnit . MINUTES ; } else if ( timeString . contains ( "microsecond" ) ) { return TimeUnit . MICROSECONDS ; } else if ( timeString . contains ( "millisecond" ) ) { return TimeUnit . MILLISECONDS ; } else if ( timeString . contains ( "second" ) ) { return TimeUnit . SECONDS ; } else if ( timeString . contains ( "hour" ) ) { return TimeUnit . HOURS ; } else if ( timeString . toLowerCase ( ) . contains ( "day" ) ) { return TimeUnit . DAYS ; } else return null ; }
Extracts and returns the time unit from a string . If the string doesn t include a unit it returns null .