public static Period parsePeriod ( String input , ConfigOrigin originForException , String pathForException ) { String s = ConfigImplUtil . unicodeTrim ( input ) ; String originalUnitString = getUnits ( s ) ; String unitString = originalUnitString ; String numberString = ConfigImplUtil . unicodeTrim ( s . substring ( 0 , s . length ( ) - unitString . length ( ) ) ) ; ChronoUnit units ; // this would be caught later anyway, but the error message // is more helpful if we check it here. if ( numberString . length ( ) == 0 ) throw new ConfigException . BadValue ( originForException , pathForException , "No number in period value '" + input + "'" ) ; if ( unitString . length ( ) > 2 && ! unitString . endsWith ( "s" ) ) unitString = unitString + "s" ; // note that this is deliberately case-sensitive if ( unitString . equals ( "" ) || unitString . equals ( "d" ) || unitString . equals ( "days" ) ) { units = ChronoUnit . DAYS ; } else if ( unitString . equals ( "w" ) || unitString . equals ( "weeks" ) ) { units = ChronoUnit . WEEKS ; } else if ( unitString . equals ( "m" ) || unitString . equals ( "mo" ) || unitString . equals ( "months" ) ) { units = ChronoUnit . MONTHS ; } else if ( unitString . equals ( "y" ) || unitString . equals ( "years" ) ) { units = ChronoUnit . YEARS ; } else { throw new ConfigException . BadValue ( originForException , pathForException , "Could not parse time unit '" + originalUnitString + "' (try d, w, mo, y)" ) ; } try { return periodOf ( Integer . parseInt ( numberString ) , units ) ; } catch ( NumberFormatException e ) { throw new ConfigException . BadValue ( originForException , pathForException , "Could not parse duration number '" + numberString + "'" ) ; } }
Parses a period string . If no units are specified in the string it is assumed to be in days . The returned period is in days . The purpose of this function is to implement the period - related methods in the ConfigObject interface .