public static UtcOffset parse ( String text ) { Pattern timeZoneRegex = Pattern . compile ( "^([-\\+])?(\\d{1,2})(:?(\\d{2}))?(:?(\\d{2}))?$" ) ; Matcher m = timeZoneRegex . matcher ( text ) ; if ( ! m . find ( ) ) { throw Messages . INSTANCE . getIllegalArgumentException ( 21 , text ) ; } String signStr = m . group ( 1 ) ; boolean positive = ! "-" . equals ( signStr ) ; String hourStr = m . group ( 2 ) ; int hourOffset = Integer . parseInt ( hourStr ) ; String minuteStr = m . group ( 4 ) ; int minuteOffset = ( minuteStr == null ) ? 0 : Integer . parseInt ( minuteStr ) ; return new UtcOffset ( positive , hourOffset , minuteOffset ) ; }
Parses a UTC offset from a string .