protected Temporal parse ( String text , Mode mode ) { if ( StringUtils . isBlank ( text ) ) { return null ; } // try to parse the date as an ISO8601 date if ( text . length ( ) >= 16 ) { try { return OffsetDateTime . parse ( text ) . toZonedDateTime ( ) ; } catch ( Exception e ) { } } // split the text into numerical and text tokens Pattern pattern = Pattern . compile ( "([0-9]+|\\p{L}+)" ) ; Matcher matcher = pattern . matcher ( text ) ; List < String > tokens = new ArrayList <> ( ) ; while ( matcher . find ( ) ) { tokens . add ( matcher . group ( 0 ) ) ; } // get the possibilities for each token List < Map < Component , Integer > > tokenPossibilities = new ArrayList <> ( ) ; for ( String token : tokens ) { Map < Component , Integer > possibilities = getTokenPossibilities ( token , mode ) ; if ( possibilities . size ( ) > 0 ) { tokenPossibilities . add ( possibilities ) ; } } // see what valid sequences we can make List < Component [ ] > sequences = getPossibleSequences ( mode , tokenPossibilities . size ( ) , m_dateStyle ) ; outer : for ( Component [ ] sequence : sequences ) { Map < Component , Integer > match = new LinkedHashMap <> ( ) ; for ( int c = 0 ; c < sequence . length ; c ++ ) { Component component = sequence [ c ] ; Integer value = tokenPossibilities . get ( c ) . get ( component ) ; match . put ( component , value ) ; if ( value == null ) { continue outer ; } } // try to make a valid result from this and return if successful Temporal obj = makeResult ( match , m_now , m_timezone ) ; if ( obj != null ) { return obj ; } } return null ; }
Returns a date datetime or time depending on what information is available