static Duration duration ( String value ) { Duration result ; if ( value != null ) { value = value . trim ( ) ; Matcher matcher = DURATION_PATTERN . matcher ( value ) ; if ( matcher . matches ( ) ) { int hours = matcher . group ( 1 ) != null ? Integer . parseInt ( matcher . group ( 1 ) ) : 0 ; int minutes = matcher . group ( 2 ) != null ? Integer . parseInt ( matcher . group ( 2 ) ) : 0 ; int seconds = matcher . group ( 3 ) != null ? Integer . parseInt ( matcher . group ( 3 ) ) : 0 ; int millis = matcher . group ( 4 ) != null ? Integer . parseInt ( matcher . group ( 4 ) ) : 0 ; result = new Duration ( hours , minutes , seconds , millis ) ; } else { throw new IllegalArgumentException ( "Unknown format for value: " + value ) ; } } else { result = null ; } return result ; }
Convert a string to a duration .