MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / of

Method of

Ports/CLDC11/src/java/time/ZoneOffset.java:13–45  ·  view source on GitHub ↗
(String offsetId)

Source from the content-addressed store, hash-verified

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);

Callers 3

ofMethod · 0.95
parseOffsetDateTimeMethod · 0.95
parseZonedDateTimeMethod · 0.95

Calls 8

charAtMethod · 0.95
substringMethod · 0.95
indexOfMethod · 0.95
splitMethod · 0.95
parseIntMethod · 0.95
lengthMethod · 0.95
ofTotalSecondsMethod · 0.95
equalsMethod · 0.65

Tested by

no test coverage detected