| 11 | } |
| 12 | |
| 13 | public static ZoneOffset of(String offsetId) { |
| 14 | if (offsetId == null) { |
| 15 | throw new NullPointerException(); |
| 16 | } |
| 17 | if ("Z".equals(offsetId)) { |
| 18 | return UTC; |
| 19 | } |
| 20 | String text = offsetId; |
| 21 | char sign = text.charAt(0); |
| 22 | if (sign != '+' && sign != '-') { |
| 23 | throw new IllegalArgumentException("Invalid offset: " + offsetId); |
| 24 | } |
| 25 | text = text.substring(1); |
| 26 | int hours; |
| 27 | int minutes = 0; |
| 28 | if (text.indexOf(':') > 0) { |
| 29 | String[] parts = split(text, ':'); |
| 30 | hours = Integer.parseInt(parts[0]); |
| 31 | minutes = Integer.parseInt(parts[1]); |
| 32 | } else if (text.length() == 2) { |
| 33 | hours = Integer.parseInt(text); |
| 34 | } else if (text.length() == 4) { |
| 35 | hours = Integer.parseInt(text.substring(0, 2)); |
| 36 | minutes = Integer.parseInt(text.substring(2)); |
| 37 | } else { |
| 38 | throw new IllegalArgumentException("Invalid offset: " + offsetId); |
| 39 | } |
| 40 | int total = hours * 3600 + minutes * 60; |
| 41 | if (sign == '-') { |
| 42 | total = -total; |
| 43 | } |
| 44 | return ofTotalSeconds(total); |
| 45 | } |
| 46 | |
| 47 | private static String[] split(String value, char ch) { |
| 48 | int pos = value.indexOf(ch); |