public static long parseDuration ( String duration ) { if ( duration == null || duration . isEmpty ( ) ) { throw new IllegalArgumentException ( "duration may not be null" ) ; } long toAdd = - 1 ; if ( days . matcher ( duration ) . matches ( ) ) { Matcher matcher = days . matcher ( duration ) ; matcher . matches ( ) ; toAdd = Long . parseLong ( matcher . group ( 1 ) ) * 60 * 60 * 24 * 1000 ; } else if ( hours . matcher ( duration ) . matches ( ) ) { Matcher matcher = hours . matcher ( duration ) ; matcher . matches ( ) ; toAdd = Long . parseLong ( matcher . group ( 1 ) ) * 60 * 60 * 1000 ; } else if ( minutes . matcher ( duration ) . matches ( ) ) { Matcher matcher = minutes . matcher ( duration ) ; matcher . matches ( ) ; toAdd = Long . parseLong ( matcher . group ( 1 ) ) * 60 * 1000 ; } else if ( seconds . matcher ( duration ) . matches ( ) ) { Matcher matcher = seconds . matcher ( duration ) ; matcher . matches ( ) ; toAdd = Long . parseLong ( matcher . group ( 1 ) ) * 1000 ; } else if ( milliseconds . matcher ( duration ) . matches ( ) ) { Matcher matcher = milliseconds . matcher ( duration ) ; matcher . matches ( ) ; toAdd = Long . parseLong ( matcher . group ( 1 ) ) ; } if ( toAdd == - 1 ) { throw new IllegalArgumentException ( "Invalid duration pattern : " + duration ) ; } return toAdd ; }
Parse a duration