public static long toPeriod ( String value , long defaultUnits ) throws ConfigException { if ( value == null ) return 0 ; long sign = 1 ; long period = 0 ; int i = 0 ; int length = value . length ( ) ; if ( length > 0 && value . charAt ( i ) == ' ' ) { sign = - 1 ; i ++ ; } while ( i < length ) { long delta = 0 ; char ch ; for ( ; i < length && ( ch = value . charAt ( i ) ) >= ' ' && ch <= ' ' ; i ++ ) delta = 10 * delta + ch - ' ' ; if ( length <= i ) period += defaultUnits * delta ; else { ch = value . charAt ( i ++ ) ; switch ( ch ) { case ' ' : period += 1000 * delta ; break ; case ' ' : if ( i < value . length ( ) && value . charAt ( i ) == ' ' ) { i ++ ; period += delta ; } else period += 60 * 1000 * delta ; break ; case ' ' : period += 60L * 60 * 1000 * delta ; break ; case ' ' : period += DAY * delta ; break ; case ' ' : period += 7L * DAY * delta ; break ; case ' ' : period += 30L * DAY * delta ; break ; case ' ' : period += 365L * DAY * delta ; break ; default : throw new ConfigException ( L . l ( "Unknown unit `{0}' in period `{1}'. Valid units are:\n '10ms' milliseconds\n '10s' seconds\n '10m' minutes\n '10h' hours\n '10D' days\n '10W' weeks\n '10M' months\n '10Y' years" , String . valueOf ( ch ) , value ) ) ; } } } period = sign * period ; // server/137w /* if (period < 0) return INFINITE; else return period; */ return period ; }
Converts a period string to a time .