public static int parseDuration ( String duration ) { if ( duration == null ) { return 60 * 60 * 24 * 30 ; } Integer toAdd = null ; if ( days . matcher ( duration ) . matches ( ) ) { Matcher matcher = days . matcher ( duration ) ; matcher . matches ( ) ; toAdd = Integer . parseInt ( matcher . group ( 1 ) ) * ( 60 * 60 ) * 24 ; } else if ( hours . matcher ( duration ) . matches ( ) ) { Matcher matcher = hours . matcher ( duration ) ; matcher . matches ( ) ; toAdd = Integer . parseInt ( matcher . group ( 1 ) ) * ( 60 * 60 ) ; } else if ( minutes . matcher ( duration ) . matches ( ) ) { Matcher matcher = minutes . matcher ( duration ) ; matcher . matches ( ) ; toAdd = Integer . parseInt ( matcher . group ( 1 ) ) * ( 60 ) ; } else if ( seconds . matcher ( duration ) . matches ( ) ) { Matcher matcher = seconds . matcher ( duration ) ; matcher . matches ( ) ; toAdd = Integer . parseInt ( matcher . group ( 1 ) ) ; } else if ( "forever" . equals ( duration ) ) { toAdd = - 1 ; } if ( toAdd == null ) { throw new IllegalArgumentException ( "Invalid duration pattern : " + duration ) ; } return toAdd ; }
Parse a duration